你首先得安装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去操作吧