When i tried to connect to mysql, there is a error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
"Driver not loaded Driver not loaded"
So i googled it, and i tried :
1.Copy sqldrivers folders to C:\Qt\Qt5.8.0\5.8\mingw53_32\plugins
2.Copy libmysql.dll to C:\Qt\Qt5.8.0\5.8\mingw53_32\bin
but the error is still there.
Is there anything i am missing?
There are 64 bit and 32 bit versions of libmysql.dll
.
rebuilding the Qt Driver is NOT a must.
With the prebuilt version of Qt5.9.1, you still need to use the 32 bit version, it worked even with the 64 version of MySQL installation. without any rebuild of QT plugins or components. Download 32 bit MySQL connector here
This was already answered here: medasumanth answer
This error generally means that Qt MySQL plugin is fine (as it is listed in available drivers), but you are a missing the MySQL dll (thus preventing the driver to load).
The way to fix it is to place libmysql.dll
somewhere in your PATH, e.g. adding the MySQL installation folder to PATH, or copy libmysql.dll
in the same folder you have your exe in.
If anyone is stupid as i am so that's for you: What basically you should do is
So basically for those who want to understand what happened here:
That "qsqlmysql" plugin is basically a qt interface that uses mysql-C connector methods. But unfortunately this connector does not distributed with Qt, so you should provide it by yourself.
If you want to distribute your software you should copy "libmysql.dll" into the folder with your ".exe" file.
I hope this will help someone save some time (3hours for me :) ).
Follow this guide
Note: you need 3 things:
a. qt-opensource-xxx-mingw492-xxx.exe for Qt Creator and Qt command Prompt.
b.qt-everywhere-opensource-src-xxx.zip for Qt source code, needed for mysql.pro file. c.mysql-connector-c-6.1.10-win32.zip needed for lib and include folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With