Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

mysql - Why QMYSQL driver not loaded in QT5.2?

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)InteliCLS Client;
    C:Program FilesInteliCLS Client;%SystemRoot%system32;%SystemRoot%;%SystemRoot%System32Wbem;%SYSTEMROOT%System32WindowsPowerShellv1.0;
    C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;
    C:Program FilesIntelIntel(R) Management Engine ComponentsIPT;
    C:Program Files (x86)IntelIntel(R) Management Engine ComponentsDAL;
    C:Program Files (x86)IntelIntel(R) Management Engine ComponentsIPT;
    C:Program FilesIntelWiFiin;
    C:Program FilesCommon FilesIntelWirelessCommon;
    C:Program Files (x86)IntelOpenCL SDK3.0inx86;
    C:Program Files (x86)IntelOpenCL SDK3.0inx64;
    C:Program FilesMicrosoftWeb Platform Installer;
    C:Program Files (x86)Microsoft ASP.NETASP.NET Web Pagesv1.0;
    C:Program Files (x86)Windows Kits8.0Windows Performance Toolkit;
    C:Program FilesMicrosoft SQL Server110ToolsBinn;
    D:SoftwareMySQLMySQL Enterprise Backup 3.8.2

XAMPP location is :

    D:XAMPP

QT location is:

    D:SoftwareQt

I have installed mysql server-5.6-64bit in D:SoftwareMySQL, and when it conflicted with mysql in XAMPP, I uninstalled mysql server-5.6-64bit.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I met with the same error and fixed it successfully by copying file

C:Program Files (x86)MySQLMySQL Connector.C 6.1liblibmysql.dll

into to

C:QtQt5.3.15.3mingw482_32in

Youtube link


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...