How to make Qt aware of the QMYSQL driver

后端 未结 7 573
春和景丽
春和景丽 2021-01-12 04:26

I\'m trying to access a MySql database from a Qt application but I get the following error:

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available dr         


        
7条回答
  •  梦毁少年i
    2021-01-12 04:53

    I compiled QT first and then realised that I need mysql as well. So I compiled mysql plugin by executing following command in QT-DIR\src\plugins\sqldrivers\mysql folder.

    Mysql plugin compile command

    qmake "INCLUDEPATH+=$$quote(C:\Program Files\MySQL\MySQL Server 5.5\include)" "LIBS+=$$quote(C:\Program Files\MySQL\MySQL Server 5.5\lib\libmysql.lib)" mysql.pro

    Plugings are then created in created in folder QT-DIR\plugins\sqldrivers. However, when I tried to use it in my code. It failed with following error.

    Error msg

    QSqlDatabase: QMYSQLDriver driver not loaded

    Solution

    After some googling and checking Path variable I realised that the Mysql server lib ( C:\Program Files\MySQL\MySQL Server 5.5\lib) directory was not in my Path variable. I expect that the dll in this folder are used by the plugin at runtime. After including Mysql server lib in Path variable everything worked smoothly. Hope this information saves some hair on other programmers scalp, as I uprooted quite a few. :D

提交回复
热议问题