qt creator using mysql plugin(driver install)

第一步building the plugins 点击打开链接
Embedded MySQL Server

The MySQL embedded server is a drop-in replacement for the normal client library. With the embedded MySQL server, a MySQL server is not required to use MySQL functionality.

To use the embedded MySQL server, simply link the Qt plugin to libmysqld instead of libmysqlclient. This can be done by replacing -lmysqlclient_r by -lmysqld in the qmake command in the section below.

Please refer to the MySQL documentation, chapter "libmysqld, the Embedded MySQL Server Library" for more information about the MySQL embedded server.

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
 make

After 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 install
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.

注意以上

 qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\MySQL Server <version>\lib\opt\libmysql.lib" mysql.pro

路径中别有空格,如有,采用双引号里加单引号方式

 qmake "INCLUDEPATH+='C:\MySQL\include'" "LIBS+='C:\MYSQL\MySQL Server <version>\lib\opt\libmysql.lib'" mysql.pro

比如:

>cd  D:\Qt\qt-win-opensource-4.8.0-mingw\4.8.0\src\plugins\sqldrivers\mysql
D:\Qt\qt-win-opensource-4.8.0-mingw\4.8.0\src\plugins\sqldrivers\mysql>qmake  "I
NCLUDEPATH+='D:/MySQL/MySQL_InstallFiles/Program Files/MySQL/MySQL Server 5.6/in
clude'" "LIBS+='D:/MySQL/MySQL_InstallFiles/Program Files/MySQL/MySQL Server 5.6
/lib/libmysql.lib'" mysql.pro
D:\Qt\qt-win-opensource-4.8.0-mingw\4.8.0\src\plugins\sqldrivers\mysql>make

此时在

D:\Qt\qt-win-opensource-4.8.0-mingw\4.8.0\src\plugins\sqldrivers\mysql\Debug

里存在qsqlmysqld4.dll, libqsqlmysqld4.a。


第二步:copy the compiling library to the specially directories

1. 拷贝libmysql.dll(D:/MySQL/MySQL_InstallFiles/Program Files/MySQL/MySQL Server 5.6/lib/)到QTDIR / bin(D:\Qt\qt-win-opensource-4.8.0-mingw\4.8.0\bin)

2. 拷贝qsqlmysqld4.dll, libqsqlmysqld4.a 到

D:\Qt\qt-win-opensource-4.8.0-mingw\4.8.0\plugins\sqldrivers

D:\Qt\qt-win-opensource-4.8.0-mingw\4.8.0\bin

D:\Qt\mingw\bin


第三步:检测

Qt Code:
  
  
  1. #include <QApplication>
  2. #include <QtSql>
  3.  
  4. int main ( int argc, char *argv [ ] )
  5. {
  6. QCoreApplication a (argc, argv );
  7. qDebug ( ) << QSqlDatabase :: drivers ( );
  8. return a. exec ( );
  9. }
output:

("QSQLITE", "QMYSQL3", "QMYSQL", "QODBC3", "QODBC") 


参考文献:http://www.qtcentre.org/threads/45295-using-mysql-plugin

Step by step compiling is (sorry for automatic translation):
In windows
After installing QT SDK (2010.05) or Nokia QT SDK Kit automatically installed some drivers to access databases, unfortunately the MySQL driver in the list is not included. Recognize that QT can not find the necessary driver is simple.

//---- Example of connection to the database ----
QSqlDatabase db = QSqlDatabase:: addDatabase ("QMYSQL", "MyConnection");
db.setHostName ("serverName");
db.setDatabaseName ("dbName");
db.setPort (3306);
db.setUserName ("login");
db.setPassword ("psw");
db.open ();
qDebug () <<db.lastError ();
//------------------------------

In this case, the console application, I get the following messages:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC3 QODBC
QSqlError (-1, "Driver not loaded", "Driver not loaded")

Recommendations installation
To address the need libraries MySQL. Required libraries are available when you install MySQL Server (for example mysql-essential-5.1.54-win32.msi) or later. We strongly recommend you install MySQL in the folder c: / MySQL / (or other folder name without spaces (MinGW does not understand spaces in the names of directories)). The installation process is sufficient to choose only one item to install - "C Include Files / Lib Files". (Hereinafter referred to as I have found in the directory C: / MySQL /).

For ease of execution of commands in a terminal to a system variable Path: "C: \ Qt \ 2010.05 \ qt \ bin \; C: \ Qt \ 2010.05 \ mingw \ bin \". These directories are executable files qmake, mingw32make, g + +. REBOOT.

In the terminal, go to QTDIR / src / plugins / sqldrivers / mysql (cd C: \ Qt \ 2010.05 \ qt \ src \ plugins \ sqldrivers \ mysql)

Perform qmake-o Makefile "INCLUDEPATH + = C: / MySQL / include" "LIBS + = C: / MySQL / lib / opt / libmysql.lib" mysql.pro

Perform mingw32-make

If all goes well, then copy the libmysql.dll from the bin folder of MySQL server installed in QTDIR / bin (I have copied in the folders specified in the PATH)

NB! If you must use a hands QTSDK copy obtained by compiling the library (qsqlmysqld4.dll, libqsqlmysqld4.a) in the following directories:
\ QtSDK \ Desktop \ Qt \ 4.7.3 (or another version) \ mingw \ plugins \ sqldrivers (if you're using a different version of it in the appropriate folder to be copied as well)
\ QtSDK \ Desktop \ Qt \ 4.7.3 (...)\ mingw \ bin
\ QtSDK \ mingw \ bin

Restart.

For MacOs X
Download and install QTSDK. After this, go to the configuration utility and install additional islhodnye codes.
Download and affix the software package MySQL (for example a mysql-5.1.53-osx10.6-x86_64.dmg, although the service I did not start.)
Next, look for a folder with qmake (/ Users/inbush/QtSDK/Desktop/Qt/471/gcc/bin/qmake)
Folder with the source MySQL (/ usr/local/mysql-5.1.53-osx10.6-x86_64/include)
Open a terminal and go to the folder plugin (Creativus: ~ inbush $ cd / Users/inbush/QtSDK/QtSources/4.7.1/src/plugins/sqldrivers/mysql)
Putting the project / Users/inbush/QtSDK/Desktop/Qt/471/gcc/bin/qmake-o Makefile "INCLUDEPATH = / usr/local/mysql-5.1.53-osx10.6-x86_64/include" "LIBS =- L / usr/local/mysql-5.1.53-osx10.6-x86_64/lib-lmysqlclient_r "mysql.pro
make
make install

FOR WINDOWS

You just can unzip files from the attachment (can't upload the compiled drivers (1.2 mb). If you need them write your e-mail and i'll send you them) and copy them in
\QtSDK\Desktop\Qt\4.7.3(or another version)\mingw\plugins\sqldrivers (if you're using a different version of it in the appropriate folder to be copied as well)
\QtSDK\Desktop\Qt\4.7.3(...)\mingw\bin
\QtSDK\mingw\bin

PS
Don't forget to add "QT += sql" in .pro file!

参考文献:http://jingyan.baidu.com/article/27fa7326ffb99146f8271fe0.html



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值