4

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 following 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?

Joel Bodenmann
  • 2,152
  • 2
  • 17
  • 44
Samir
  • 3,923
  • 9
  • 36
  • 43
  • I recommend reading the following excellent guide: http://christopher.rasch-olsen.no/2009/04/14/qt-45-and-mysql-plugin-with-mingw-on-windows-xp/ (with comments) - it helped me to solve exactly the same problem. – Michael Pliskin Mar 11 '11 at 07:35

2 Answers2

3

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

Lukáš Lalinský
  • 40,587
  • 6
  • 104
  • 126
  • 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 Oct 08 '09 at 04:28
  • 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 Oct 08 '09 at 06:18
  • 1
    Is `libmysql.dll` somewhere where `qsqlmysql4.dll` can find it? – Lukáš Lalinský Oct 08 '09 at 07:29
  • 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 Oct 08 '09 at 10:34
  • Hi Lukas, I just found libmysql.dll in C:\mysql-5.1.39-win32\lib\opt. What to do now ? – Samir Oct 08 '09 at 10:40
  • 1
    Copy it to the application directory, or somewhere to `%PATH%`. – Lukáš Lalinský Oct 08 '09 at 10:48
  • the link is dead now – Shihe Zhang Jun 15 '17 at 01:23
0

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
  • 3,923
  • 9
  • 36
  • 43
  • I suggest to use Qt Sdk which comes with Mingw. – Sharique Oct 12 '09 at 13:08
  • 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 Nov 20 '09 at 11:10
  • Anyway, from Qt command prompt "D:\Qt\qt\src\plugins\sqldrivers\mysql>configure -release -qt-sql-mysql -l mysql -I c:\mysql\include -L c:\mysql\lib\opt" executes without any error. Also "mingw32-make" works fine and produces qsqlmysql4.dll & libqsqlmysql4.a in "D:\Qt\qt\plugins\sqldrivers". I thought it was over!!! But still qDebug()< – Samir Nov 20 '09 at 12:23
  • The link is dead now – Shihe Zhang Jun 15 '17 at 01:30