views:

2374

answers:

2

Platform: Windows XP, Qt Creator Ide 4.5.2

MySql is setup here as well.

I want to establish database connection with Qt and mysql. The line

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

generates error like below: QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC

It seems QMYSQL driver is absent here. What to do ?

+1  A: 

You need to build the Qt/MySQL driver. See the documentation.

Lukáš Lalinský
Hello Lukas, I was too new to understand that I had to open the visual studio command prompt, nmake worked fine and it produced qsqlmysql4.dll.
Samir
Now I copied the qsqlmysql4.dll to %QtCreatorinstallationDir%\qt\plugins\sqldrivers. And the above code shows above errors still. How to let QtCreator recognize the qsqlmysql4.dll ?
Samir
Is `libmysql.dll` somewhere where `qsqlmysql4.dll` can find it?
Lukáš Lalinský
Hello Lukas, no libmysql.dll is not there at all. qsqlmysql4.dll is in C:\qt-win-opensource-src-4.5.2\plugins\sqldrivers. And the C:\qt-win-opensource-src-4.5.2 directory does not contain libmysql.dll.
Samir
Hi Lukas, I just found libmysql.dll in C:\mysql-5.1.39-win32\lib\opt. What to do now ?
Samir
Copy it to the application directory, or somewhere to `%PATH%`.
Lukáš Lalinský
A: 

The output in my pc as instructed in the documentation is:

*C:>cd C:\qt-win-opensource-src-4.5.2\src\plugins\sqldrivers\mysql

C:\qt-win-opensource-src-4.5.2\src\plugins\sqldrivers\mysql>qmake -o Makefile "INCLUDEPATH+=C:\mysql-5.1.39-win32\include" "LIBS+=C:\mysql-5.1.39-win32\lib\opt\LIBMYSQL.LIB" mysql.pro

C:\qt-win-opensource-src-4.5.2\src\plugins\sqldrivers\mysql>"C:\Program Files\Microsoft Visual Studio 8\VC\bin\nmake"

Microsoft (R) Program Maintenance Utility Version 8.00.50727.762 Copyright (C) Microsoft Corporation. All rights reserved.

    "C:\Program Files\Microsoft Visual Studio 8\VC\bin\nmake.exe" -f Makefile.Debug all

Microsoft (R) Program Maintenance Utility Version 8.00.50727.762 Copyright (C) Microsoft Corporation. All rights reserved.

    cl -c -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189

-DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FRO M_ASCII -DQT_DLL -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I". .......\include\QtCore" -I"........\include\QtSql" -I"........\include" -I"c:\mysql-5.1.39-win32\include" -I"........\include\ActiveQt" -I"tmp\moc\d ebug_shared" -I"........\mkspecs\win32-msvc2005" -Fotmp\obj\debug_shared\ @C: \DOCUME~1\test\LOCALS~1\Temp\nm38.tmp

NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\bin\c l.EXE"' : return code '0xc0000135' Stop.

NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\bin\n make.exe"' : return code '0x2'*

What might be the problem? Is it the nmake or something else? I did go through the web but I'm stuck here.

Samir
I suggest to use Qt Sdk which comes with Mingw.
Sharique
As http://www.rag.com.au/linux/qt4howto.html says after executing the command "configure -platform win32-g++ -static -release -qt-sql-sqlite -qt-sql-mysql -l mysql -I c:\mysql\include -L c:\mysql\lib\opt" got the error message"copy qmake.exe D:\Qt\qt\bin\qmake.exe 1 file(s) copied.Creating makefiles in src...Generating Makefiles...execute: Unknown error (-spec) (win32-g++) (-r) (D:/Qt/qt/projects.pro) (-o) (D:/Qt/qt)Qmake failed, return code -1"so can't execute the next command "mingw32-make"Whan went wrong actually ?
Samir
Samir