首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > QT开发 >

Qt4连接MySQL的有关问题

2012-03-30 
Qt4连接MySQL的问题C/C++ codeQSqlDatabase mysqldbQSqlDatabase::addDatabase(QMYSQL)mysqldb.setHos

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这类的

热点排行