-->

QT MySql connectivity using Windows XP, Qt Creator

2019-01-28 05:09发布

问题:

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:

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.



回答2:

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



回答3:

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.