如何使用QODBC / QODBC3 Qt驱动程序正确连接到Excel文件?
在第一次,我建造了一个类似的驱动程序(在cmd中)
> cd%QTPATH%\ src \ plugins \ sqldrivers \ odbc
> qmake odbc.pro
> NMAKE
然后在qsqlodbc4.dll
%QTPATH%\plugins\sqldrivers
文件
我使用了这段代码
#include <QApplication>
#include <QtGui>
#include <QtSql>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
//QComboBox myCombo;
//excel stuff
QSqlDatabase dbExcel = QSqlDatabase::addDatabase("QODBC","dbExcel");
// i thought mayde that would work
// dbExcel.setDatabaseName("C:\databases\test.xlsx");
//i tried connection string too
dbExcel.setDatabaseName(QString("DRIVER={Microsoft Excel Driver (*.xlsx)}; READONLY=FALSE; FIL={MS Excel}; DBQ=C:\databases\test.xlsx"));
if(!dbExcel.open())
{
QSqlError er = dbExcel.lastError();
QMessageBox::information(0, "Error", er.text());
}
//...................
return app.exec();
}
在那里我发现了这个错误(它翻译成:
[Microsoft][ODBC driver manager] Data source not found and default driver not set. QODBC3: Unable to connect
)
UPD
此外,它说司机是可用的
QSqlDatabase: available drivers: QIBASE QSQLITE QODBC3 QODBC