当前位置: 代码迷 >> QT开发 >> Qt4连接MySQL的有关问题
  详细解决方案

Qt4连接MySQL的有关问题

热度:35   发布时间:2016-04-25 04:56:31.0
Qt4连接MySQL的问题
C/C++ code
    QSqlDatabase mysqldb=QSqlDatabase::addDatabase("QMYSQL");    mysqldb.setHostName(QObject::tr("10.0.1.209"));    mysqldb.setDatabaseName(QObject::tr("skystore"));    mysqldb.setUserName(QObject::tr("skystore"));    mysqldb.setPassword(QObject::tr("8888"));    if(!mysqldb.open())    {        QMessageBox::critical(0,QObject::tr("DataBase Error!"),mysqldb.lastError().text());    }else{        QMessageBox::critical(0,QObject::tr("DataBase OK!"),QObject::tr("DataBase OK!"));    }

提示Driver not loaded,连接远程的数据库还要装MySQL吗?网上说要编译MySQL驱动,难道Qt不自带吗

------解决方案--------------------
是要自己编译驱动,文档里有的:
How to Build the QMYSQL Plugin on Windows

You need to get the MySQL installation files. Run SETUP.EXE and choose "Custom Install". Install the "Libs & Include Files" Module. Build the plugin as follows (here it is assumed that MySQL is installed in C:\MySQL):

 cd %QTDIR%\src\plugins\sqldrivers\mysql
 qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\MySQL Server <version>\lib\opt\libmysql.lib" mysql.pro
 nmake
If you are not using a Microsoft compiler, replace nmake with make in the line above.

Note: This database plugin is not supported for Windows CE.

Note: Including "-o Makefile" as an argument to qmake to tell it where to build the makefile can cause the plugin to be built in release mode only. If you are expecting a debug version to be built as well, don't use the "-o Makefile" option.
------解决方案--------------------
探讨

这么麻烦啊,那是不是Qt不擅长做企业应用啊,比如ERP这类的
  相关解决方案