[SOLVED] Qt connect to XLSX file with ODBC driver


I have that code, that I took from Qt wiki:

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={Microsoft Excel Driver (*.xls)};DBQ=" + QString("sht.xlsx"));
    QSqlQuery query("select * from [" + QString("Sheet1") + "$]");
    // Select range, place A1:B5 after $
    while (query.next())
        QString column1= query.value(0).toString();
        qDebug() << column1;
else {
    qDebug() << db.lastError().text();

But it doesn’t connect 🙁 I can’t understand why:

[Microsoft] [Driver Manager ODBC] Data source name not found and no driver specified, the default QODBC3: Unable to connect


It was nedeed tp specify full path and set full name as in ODBC:

DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};

As always stack was useless. Guys here can answer only on noob questions, every real problem will stay here without answer.

Answered By – Maxim

Answer Checked By – Senaida (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *