My program is write with QT5.2 and use mysql. I heared that QT5.2 contains MYSQL driver already. However, when I compile and run my program, it is compiled successfully but runned failed with error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
My programe is like this:
QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("tradingsystem");
db.setUserName("root");
db.setPassword("");
if(!db.open())
{
//.....;
}
And in .pro I add this:
QT += sql
Mysql is provided by XAMPP.My OS is win7-x64-sp1-ultimate, and XAMPP Version 1.8.2.System Path is as follow:
C:\Program Files (x86)\SepanderSoft;
C:\Program Files (x86)\Intel\iCLS Client\;
C:\Program Files\Intel\iCLS Client\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files\Intel\WiFi\bin\;
C:\Program Files\Common Files\Intel\WirelessCommon\;
C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86;
C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;
C:\Program Files\Microsoft\Web Platform Installer\;
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;
C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;
C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;
D:\Software\MySQL\MySQL Enterprise Backup 3.8.2\
XAMPP location is :
D:\XAMPP
QT location is:
D:\Software\Qt
I have installed mysql server-5.6-64bit in D:\Software\MySQL, and when it conflicted with mysql in XAMPP, I uninstalled mysql server-5.6-64bit.
I met with the same error and fixed it successfully by copying file
C:\Program Files (x86)\MySQL\MySQL Connector.C 6.1\lib\libmysql.dll
into to
C:\Qt\Qt5.3.1\5.3\mingw482_32\bin
Youtube link
I was facing the same issue and even "Hồ Sĩ Sơn"s solution didn't work. I then found out that I had installed a 64-bit version of MySQL and was trying it on a 32-bit version of Qt.
Copying the dll from the below location didn't work:
C:\Program Files\MySQL\MySQL Connector.C 6.1\lib\libmysql.dll
Instead download the 32-bit version of libmysql.dll from:
https://dev.mysql.com/downloads/connector/c/
and the copy it to your mingw folder.
In my case, I had to copy the DLL to msvc2010 folder since I am using Visual Studio compiler:
C:\Qt\5.4\msvc2010_opengl\bin
Hope this helps. :)
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