QSqlDatabase: QODBC driver not loaded - problem
-
Hi
I have the following code :
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QDebug> #include <QSqlDatabase> #include <QSqlQuery> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QSqlDatabase db = QSqlDatabase::addDatabase("QODBC"); db.setDatabaseName("Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=d:/TEST"); db.open(); }
after pressing button I see the messages "
QSqlDatabase: QODBC driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7"How to solve the problem ?
How to load the driver.I use Windows 7 64bit.
Regards
Artur -
It's a "feature" of Qt 5.6, see https://bugreports.qt.io/browse/QTBUG-49420 for report and solution
-
Thank you for information. Now Everything is clear and know why I spent so many hours and still problem with ODBC.
ODBC Build Steps
cd c:/Qt/Qt5.6.0/5.6/Src/qtbase/src/plugins/sqldrivers/odbc
qmake odbc.pro
nmake
nmake release
nmake install
nmake release-installI am quite new in QT so I do not know how to do above procedure. Where can I download odbc.pro ?
-
Hi @Arturs,
you need to download the source files of Qt 5.6 and then take a look here http://doc.qt.io/qt-5.6/sql-driver.html#qodbc-for-open-database-connectivity-odbc, section How to Build the ODBC Plugin on Windows. It says:The ODBC header and include files should already be installed in the right directories. You just have to build the plugin as follows:
cd %QTDIR%\qtbase\src\plugins\sqldrivers\odbc qmake odbc.pro nmake
If you are not using a Microsoft compiler, replace nmake with make in the line above.
Hope this helps
-
@Arturs
The lines above should create your necessary libraries (dlls / libs).
I have done this a long time ago, so i do not remeber where the files are created, sorry for that.Update:
I am not quite sure but take a look at this directory:%QTDIR%\qtbase\plugins\sqldrivers
-
I am not sure that I install plugin in proper way.
In readme file is the following information:
"You will need ODBC development headers and libraries installed before
compiling this plugin."Where to find headers and libriaries ?
What I did:
- downloaded qt sources
- open odbc catalogue - cd %QTDIR%\qtbase\src\plugins\sqldrivers\odbc in command prompt
- used the command - qmake odbc.pro
before using the command in the catalogue were only the files:
main.cpp
odbc.json
odbc.proafter compiling are more files but there are not any dll files
-
-
You are in the wrong directory. I think in your case it should be:
D:\qt-everywhere-opensource-src-5.6.0\qt-everywhere-opensource-src-5.6.0\qtbase\plugins\sqldrivers
or download the new Qt 5.6.1 (released on 8th of June 2016), like @hskoglund said.
-
I installed new version of Qt 5.6.1 for Windows 64-bit (VS 2015, 836 MB) (info) but now during compilation I have the following error:
"Error while building/deploying project Gunsbase (kit: Desktop Qt 5.6.1 MSVC2015 64bit) When executing step "Make"