Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt 5 ODBC driver issue

Tags:

qt

odbc

qt5

I am trying to use ODBC driver in one of my Qt5 project.

I compiled QODBC driver and copied the driver dlls to the Qt\Qt5.0.0\5.0.0\msvc2010\plugins\sqldrivers folder.

When I try the following code:

 QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");

I get the following error:

QSqlDatabase: QODBC driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3

Same error is encountered if I tried loading QODBC3.

Even though QODBC and QODBC3 drivers are present, Qt still could not load QODBC driver.

I am running Windows 7 (64 bit) PC.

Has anybody encountered such error? Any clues on what might be wrong ?

like image 279
Mugunth Avatar asked Dec 07 '25 21:12

Mugunth


1 Answers

I found the issue was caused due to incorrect Visual studio versions used while compiling odbc sql driver.

I had both VS 2008 and VS 2010 in my computer. My Qt5.0 was using VS2010. But when I compiled the odbc sql driver, I had used VS2008. And that caused the problem.

Qt was able to detect the sql odbc driver but could not load it.

I solved this by recompiling the odbc driver using VS2010 and odbc driver works pefectly.

Here are the steps to compile and use sql odbc drivers in Qt 5.0

  1. open qt command prompt:
  2. this can be found in start menu under Qt
  3. set vc++ environment variables:

    • To do this , cd into to the C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ folder and run vcvarsall.bat
      Important point to note is, compile the driver using the same version of Visual Studio thats used by Qt.
  4. cd into \Qt5.0.0\5.0.0\Src\qtbase\src\plugins\sqldrivers\odbc source folder

  5. qmake odbc.pro

  6. nmake

    • If it runs correctly, the compiled qsqlodbc.dll and qsqlodbcd.dll will be available in \Qt5.0.0\5.0.0\Src\qtbase\plugins\sqldrivers folder.
  7. While deploying qt based application, qsqlodbc.dll (release version) need to be copied to sqldrivers folder.
like image 156
Mugunth Avatar answered Dec 11 '25 03:12

Mugunth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!