简体   繁体   中英

QT : QSqlDatabase: QMYSQL driver not loaded [WINDOWS]

Salam Alikom

Hi Everyone

i'm trying to create a QT interface to connect to MYSQL database but it's giving alwas an error

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7

this my code

QSqlDatabase db1 = QSqlDatabase::addDatabase("QMYSQL");
db1.setHostName("localhost");
db1.setUserName("root");
db1.setPassword("");
db1.setDatabaseName("journal_machine");

i tried some solutions but it doesn't work

this my Configuration

QT Creator 2.8.1

QT 5.1.1 (MSVC2010 , 32bit)

Windows 10 64 bit

MySQL 5.6.17 installed with WampServer 2.5 (64bit)

Thanks in advance

It's late to answer, but this may be useful for future readers.

For project kit 64 bit use MySql 64 bit , and for project kit 32 bit use MySql 32 bit .

note: xx: 64 or 32

  • qsqlmysql.dll and qsqlmysqld.dll files should be exist in <QtDir>\\mingw73_xx\\plugins\\sqldrivers folder.

  • libqsqlmysql.a and libqsqlmysqld.a files should be exist in <QtDir>\\mingw73_xx\\lib folder.

  • libmysql.dll file should be exist in <QtDir>\\mingw73_xx\\bin folder.

Now, you can build your project.

// comment:

If "QMYSQL driver not loaded" error persists, follow instrument:

  1. Copy MySql folder from Program Files to a simple path. (for example: "D:/MySQL")

  2. Go to "\\Src\\qtbase\\src\\plugins\\sqldrivers\\mysql" folder

  3. Open mysql.pro as text.

  4. Comment QMAKE_USE += mysql line using '#'. ( #QMAKE_USE += mysql )

  5. Add following lines after that:

    LIBS += 'D:/MySQL/lib/libmysql.lib'

    INCLUDEPATH += 'D:/MySQL/include'

    DEPENDPATH += 'D:/MySQL/include'

  6. Save file.

  7. Open Qt 5.13.1 (MinGW 7.3.0 xx-bit).exe from start menu (for example).

  8. Go to <QtDir>\\Src\\qtbase\\src\\plugins\\sqldrivers folder (use 'cd' command).

  9. Use qmake mysql.pro command.

  10. Use mingw32-make command.

  11. If compile done successfully, go to <QtDir>\\Src\\qtbase\\src\\plugins\\sqldrivers\\plugins\\sqldrivers folder.

  12. Copy qsqlmysql.dll and qsqlmysqld.dll files into <QtDir>\\mingw73_xx\\plugins\\sqldrivers folder.

  13. Copy libqsqlmysql.a and libqsqlmysqld.a files into <QtDir>\\mingw73_xx\\lib folder.

// comment:

If error persists, follow instrument:

  1. Download "MySQL Connector C 6.1" program and install it.
  2. Go to <MySQL Connector C 6.1 Dir>\\bin folder.
  3. Copy libmysql.dll file into <QtDir>\\mingw73_xx\\bin folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM