PDA

View Full Version : How I can activate QODBC in Qt4 for windows



vcp
23rd June 2010, 13:37
Hi people,

I have a doubt about how to enable the ODBC in Qt4 for Windows.
I compiled the plugins correctly, but nothing happens.
The QSqlDatabase:: drivers () shows me only: QSQLLITE, QMYSQL3 and QMYSQL.

I've wich to recompile the Qt4 on windows to enable QODBC?

I'm using: qt-sdk-win-opensource-2010.03

I've done much research on the web and this forum, but the answers are many
and different. And then I would like something more objective.

Thanks in advance

ChrisW67
23rd June 2010, 23:38
My copy of the Qt SDK (2010.02.1) already has built and functional QODBC driver support out-of-the-box. I cannot imagine that Nokia would have not done the same build for 2010.03.

If your problem is evident when the app is run on a deployed machine then you have probably not deployed the necessary sqldrivers plugins.

vcp
24th June 2010, 12:14
Hi,

That is, the nokia doesn't compile the sdk for windows that supports ODBC, you have to recompile the sdk to get it.
If it is, I think nokia is wrong in this attitude. This will only hinder, not help, nothing at all!

Thanks

ChrisW67
25th June 2010, 02:59
Qt SDK 2009.03 already has built and functional QODBC driver support out-of-the-box.
Qt SDK 2010.02.1 already has built and functional QODBC driver support out-of-the-box.
I have deployed ODBC-using applications using both of the above without ever rebuilding any part of Qt on Windows.

The copy of Qt SDK 2010.04 I just downloaded has ODBC support built out-of-the-box. Open Windows Explorer, navigate to your equivalent of "C:\Qt\2010.04\qt\plugins\sqldrivers", observe qsqlodbc4.dll and qsqlodbcd4.dll.



#include <QtCore>
#include <QtSql>
#include <QDebug>

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);

qDebug() << QSqlDatabase::drivers();
return 0;
}

and its output:


Starting C:\temp\debug\temp.exe...
("QSQLITE", "QODBC3", "QODBC")


No amount of you repeating that Qt SDK doesn't include ODBC out-of-the-box will make it so.

vcp
29th June 2010, 18:05
hi,

I installed 2010.04 and realy saw the dlls, but when I compile your example or other code
SqlDatabase:: drivers () shows:



("QSQLITE", "QMYSQL3", "QMYSQL")

// if I try open a database
QSqlDatabase: QODBC driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL3 QMYSQL
QSqlError(-1, "Driver not loaded", "Driver not loaded")


There is, perhaps, some explanation for this behavior?

Thanks a lot

vcp
1st July 2010, 14:14
Hi (again) all,

After searching a lot, I would put in this forum, for my solution to: ODBC Driver not loaded problem in WindowsXP using Qt 2010.0x

Compiling odbc modules and placing them in the right places, they were not loaded.
Searching within files Configure.cache and .gmake (Qt\2010.0x\qt) and I noticed that the use of instruction sql-plugins + = odbc. So I put this option in my .pro file.
I compiled the application and the result was that the odbc was successfully activated.

("QSqlLite "," QODBC3 "," QODBC "," QMYSQL3 "," QMYSQL")

So, if any of you are having a similar problem try using in the .pro file the instruction:

src.pro:

sql-plugins += odbc

bye.

ChrisW67
2nd July 2010, 06:45
There is, perhaps, some explanation for this behavior?
The only explanation for this is that the program is running with libraries other than the ones shipped in the SDK. The libraries shipped in the SDK give the result in my earlier post. The dead give away is that the Qt SDK (Windows) does not have any MYSQL support out-of-the-box. If you really want to find out what is going on try using Dependency Walker (http://www.dependencywalker.com/) and/or Process Monitor (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) on your executable running in the environment in which it fails.

I'll say it once again. You do not have to build any part of Qt in order to get ODBC support with the Mingw-based Qt SDK on Windows. It is there out of the box. You need do nothing more than add:
CONFIG += sql to your PRO file to link the relevant libraries, and make sure when you deploy the correct libraries and drivers go with it.