qt creator using mysql plugin(driver install)
来源:互联网 发布:淘宝网页版怎么看微淘 编辑:程序博客网 时间:2024/05/21 03:26
第一步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 "INCLUDEPATH+='D:/MySQL/MySQL_InstallFiles/Program Files/MySQL/MySQL Server 5.6/include'" "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
第三步:检测
output:
#include <QApplication> #include <QtSql> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); qDebug() << QSqlDatabase::drivers(); return a.exec(); }
("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
- qt creator using mysql plugin(driver install)
- ros 安装 qt creator plugin
- [Qt creator+Linux]mysql数据库使用问题:mysql driver not loaded
- CppSupport Plugin 1.3.x for Qt Creator
- CppSupport Plugin 1.3.x for Qt Creator
- How install Qt Creator for ubuntu 16.04
- Using the Maya API with Qt Creator
- Mysql InnoDB Plugin安装 install
- Qt Creator编译mysql驱动
- QT 5.5 creator 连接MYSQL
- Using the Qt Creator IDE with non Qt projects
- 安装 ROS Qt Creator Plugin's 错误记录
- Qt Creator
- Qt Creator
- qt creator
- qt creator
- qt creator
- qt creator
- fedora21-安装搜狗输入法
- 关于Linux的发音
- Uri类讲解
- Convert Sorted Array to Binary Search Tree (Java)
- php读取操作大文件,超出内存大小,三种方法
- qt creator using mysql plugin(driver install)
- 多线程 学习笔记<4> 进程与线程的区别联系
- SQLServer查找哪些存储过程是已经加密的
- Windows 下实现RST
- Intellij IDEA 中安装Angular 插件方法
- struts框架下,java导出excel(JXL导出)
- SSH框架之Spring(1)——综述
- Java基础----单例模式
- linux 下安装中文输入法