Configure MySQL Database Driver for QT

I am working on a QT project on Ubuntu and I needed to use the MySql database driver for it. In previous versions of QT, it used to be the default installed library but with QT 2010.2 installation (4.6 and above), it is not the default installation. So, it requires to configure the MySql header files and then configure the QT to use the file. Here are the steps which worked for me.

1. First of all, we need to install the MySql Deveoper Libraries on Ubuntu. This will be required by QT to compile the MySql driver.

sudo apt-get install libmysqlclient15-dev

2. After this installation is successful. It will create the folder “/usr/incluce/mysql” in the Ubuntu installation and it will also install the lib files in “/usr/lib/mysql”. We will need this to compile the QT MySql driver:

cd $QTDIR/src/plugins/sqldrivers/mysql
qmake "INCLUDEPATH+=/usr/include/mysql" "LIBS+=-L/usr/lib/mysql -lmysqlclient_r" mysql.pro
make

3. After this, just need to compile the QT code using the “QMYSQL” driver.

Advertisements

Tags: , ,

About prres

I have been working with Microsoft Tools and Technologies for 9 years. Most of my work include architecting and developing with C#, ASP.Net, Silverlight and SQL Server.

6 responses to “Configure MySQL Database Driver for QT”

  1. echo says :

    i have the same problem.
    when i execute ‘make’ i get a lot of errors like :

    main.cpp:44:30: error: qsqldriverplugin.h: No such file or directory
    main.cpp:45:25: error: qstringlist.h: No such file or directory

    and error list includes other include files in these files and so on.i found these files on my HDD in

    $QTDIR/doc/html/qsqldriverplugin.html
    $QTDIR/include/Qt/qsqldriverplugin.h
    $QTDIR/include/QtSql/qsqldriverplugin.h
    $QTDIR/src/sql/kernel/qsqldriverplugin.h

    when i change the missing file with full path, the old error disapears but i still get the same error for every included file in project. i think the include file (variable) maybe is set to wrong path or … please help me

    i am using Ubuntu lucid and qtsdk-2010.05

  2. echo says :

    [SOLVED]
    for other viewers that have the same problem in QMYSQL driver for QT
    ‘/home/echo’ is my home path. you may need to change ‘echo’ to your user account name

    cd ~/qtsdk-2010.05/qt/src/plugins/sqldrivers/mysql
    qmake “INCLUDEPATH+=/usr/include/mysql” “INCLUDEPATH+=/home/echo/qtsdk-2010.05/qt/include” “LIBS+=-L/usr/lib/mysql -lmysqlclient_r” mysql.pro

    then i edit ‘main.cpp’ and change include command in line 42 and 43 like this:

    #include “/home/echo/qtsdk-2010.05/qt/include/Qt/qsqldriverplugin.h”
    #include “/home/echo/qtsdk-2010.05/qt/include/Qt/qstringlist.h”

    then i install libqt4-dev for continuing the compile process and
    then execute ‘make’.

    ‘libqsqlmysql.so’ file created and i copied it in my plugins path

    cd /home/echo/qtsdk-2010.05/qt/plugins/sqldrivers/
    cp /usr/lib/qt4/plugins/sqldrivers/libqsqlmysql.so ./

    QT now detect QMYSQL driver
    cheers

  3. Paul says :

    and I’ve according to steps of echo next:

    qmake “INCLUDEPATH+=/usr/include/mysql” “INCLUDEPATH+=/home/paul01/QtSDK/q/home/paul01/QtSDK/Desktop/Qt/4.8.0/gcc/include” “LIBS+=-L/usr/lib/mysql -lmysqlclient_r” mysql.pro
    ***Unknown option -lmysqlclient_r”

    and :

    main.cpp:60: error: ‘QMYSQLDriverPlugin’ has not been declared
    main.cpp:60: error: ISO C++ forbids declaration of ‘QMYSQLDriverPlugin’ with no type
    main.cpp: In function ‘int QMYSQLDriverPlugin()’:
    main.cpp:61: error: only constructors take base initializers
    main.cpp:63: warning: no return statement in function returning non-void
    main.cpp: At global scope:
    main.cpp:65: error: expected constructor, destructor, or type conversion before ‘*’ token
    make: *** [main.o] Error 1

    why?

    Thanks

  4. Shamir Shakir (@dewsworldTweet) says :

    echo, man you’re awesome. Thanks. I just solved the big issue.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: