• 4276阅读
  • 2回复

请问有人能给讲讲Qt连接mysql的步骤吗?谢谢大家 [复制链接]

上一主题 下一主题
离线zhangrui241
 
只看楼主 倒序阅读 楼主  发表于: 2009-03-30
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
我想用Qt连接mysql,但是不知道怎么连接,我去mysql.com下了个C++的驱动,然后不知道怎么用了,请教大家!
离线foxyz

只看该作者 1楼 发表于: 2009-03-30
你首先得安装mysql for Qt的driver,请参照Qt的说明文档

。。。。。\doc\html\sql-driver.html
How to Build the QMYSQL Plugin on Unix and Mac OS X
You need the MySQL header files and as well as the shared library libmysqlclient.so. Depending on your Linux distribution you may need to install a package which is usually called "mysql-devel".

Tell qmake where to find the MySQL header files and shared libraries (here it is assumed that MySQL is installed in /usr/local) and run make:

cd $QTDIR/src/plugins/sqldrivers/mysql
qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro
makeAfter installing Qt, as described in the Installing Qt on X11 Platforms document, you also need to install the plugin in the standard location:

cd $QTDIR/src/plugins/sqldrivers/mysql
make installHow 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
nmakeIf 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.


然后,你就使用QSqlDatabase以及QSqlQuery去操作吧
离线zhangrui241
只看该作者 2楼 发表于: 2009-03-30
谢谢你了。
我试试连下。
快速回复
限100 字节
 
上一个 下一个