PDA

View Full Version : using mysql plugin



coding_neo
16th October 2011, 14:34
Hello:

I have successfully built the mysql plugin for QT. The build process resulted in the following 4 files:

qsqlmysql4.dll
qsqlmysql4.lib
qsqlmysqld4.dll
qsqlmysqld4.lib.

I copied the above files to the plugins directory of QT, and the .dll's to C:\windows\system32
Then I wrote sample code to test


#include <QApplication>
#include <QtSql>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << QSqlDatabase::drivers();
return a.exec();
}


The code compiles, links and runs fine but i get no output.
According to http://www.pikopong.com/blog/2010/04/11/how-to-enable-mysql-support-in-qt-sdk-for-windows/

The above code should output :


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


What am I doing wrong?

inbush
16th October 2011, 16:13
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!