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:
Copy MySql folder from Program Files to a simple path. (for example: "D:/MySQL")
Go to "\\Src\\qtbase\\src\\plugins\\sqldrivers\\mysql" folder
Open mysql.pro as text.
Comment QMAKE_USE += mysql
line using '#'. ( #QMAKE_USE += mysql
)
Add following lines after that:
LIBS += 'D:/MySQL/lib/libmysql.lib'
INCLUDEPATH += 'D:/MySQL/include'
DEPENDPATH += 'D:/MySQL/include'
Save file.
Open Qt 5.13.1 (MinGW 7.3.0 xx-bit).exe
from start menu (for example).
Go to <QtDir>\\Src\\qtbase\\src\\plugins\\sqldrivers
folder (use 'cd' command).
Use qmake mysql.pro
command.
Use mingw32-make
command.
If compile done successfully, go to <QtDir>\\Src\\qtbase\\src\\plugins\\sqldrivers\\plugins\\sqldrivers
folder.
Copy qsqlmysql.dll
and qsqlmysqld.dll
files into <QtDir>\\mingw73_xx\\plugins\\sqldrivers
folder.
Copy libqsqlmysql.a
and libqsqlmysqld.a
files into <QtDir>\\mingw73_xx\\lib
folder.
// comment:
If error persists, follow instrument:
<MySQL Connector C 6.1 Dir>\\bin
folder.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.