1

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

Community
  • 1
  • 1
Amine
  • 100
  • 3
  • 10
  • Is the libmysql.dll in your PATH? Are the Qt plugins in your PATH? – OnWhenReady May 02 '16 at 09:07
  • Possible duplicate of [QMYSQL driver loading error](http://stackoverflow.com/questions/31821329/qmysql-driver-loading-error) – agold May 02 '16 at 12:08
  • i have MySQL 5.6 installed on ` C:\wamp\bin\mysql\mysql5.6.17 ` and i have `libmysql.dll` in `C:\wamp\bin\mysql\mysql5.6.17\lib` @OnWhenReady what should i do exactly !! – Amine May 02 '16 at 12:12
  • As a first attempt: Put the dll in the directory of the executable. – OnWhenReady May 02 '16 at 12:17
  • i did past `libmysql.dll` in `C:\Users\Amine\Documents\QT\build-Journal_Machine-Desktop_Qt_5_1_1_MinGW_32bit-Debug\debug` `Journal_Machine.exe journal_machine.o libmysql.dll libmysqld.dll main.o moc_journal_machine.cpp moc_journal_machine.o` But still the same problem :( – Amine May 02 '16 at 13:23

1 Answers1

1

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.
Morteza M
  • 130
  • 6