ODBC driver use in Qt

半腔热情 提交于 2019-12-05 10:43:18

If you need to access an MS Access database with Qt, you don't need (if I'm not mistaken) to install anything regarding drivers (everything should be already there).

You can connect to a database with a connection string. Something like this :

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("Driver={Microsoft Access Driver (*.mdb, *.accdb)};DSN='';DBQ=C:\\path\\to\\mydatabase.mdb");
bool Success = db.open();

I had the same Problem.

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC","AccessDB");
db.setDatabaseName("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=C:/path/to/Database.mdb");
bool success = db.open();

works for me.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!