pikopong

it's all about knowledge

How to enable MySQL support in Qt SDK for Linux

with 5 comments

  1. Download Qt SDK for Linux/X11 at Qt Software.
  2. Install it anywhere you want, just make sure you remember the path.
  3. To build MySQL as a plugin, you need to know two other paths:
    • Your MySQL header files directory. It should be something like this:
      decimal.h   m_string.h      my_dbug.h    my_list.h        my_sys.h     mysql_embed.h    mysqld_error.h  sql_state.h        typelib.h
      errmsg.h    my_alloc.h      my_dir.h     my_net.h         my_xml.h     mysql_time.h     raid.h          sslopt-case.h
      keycache.h  my_attribute.h  my_getopt.h  my_no_pthread.h  mysql.h      mysql_version.h  readline.h      sslopt-longopts.h
      m_ctype.h   my_config.h     my_global.h  my_pthread.h     mysql_com.h  mysqld_ername.h  sql_common.h    sslopt-vars.h
    • Your MySQL lib files directory. Something like this:
      libdbug.a    libmyisammrg.a      libmysqlclient.so@         libmysqlclient_r.a    libmysqlclient_r.so.15@      libmysys.a
      libheap.a    libmysqlclient.a    libmysqlclient.so.15@      libmysqlclient_r.la*  libmysqlclient_r.so.15.0.0*  libvio.a
      libmyisam.a  libmysqlclient.la*  libmysqlclient.so.15.0.0*  libmysqlclient_r.so@  libmystrings.a
  4. For Slackware 12.2, it should be:
    1
    2
    
    /usr/include/mysql	# MySQL header directory
    /usr/lib/mysql		# MySQL libraries
  5. Go to your Qt SDK installation directory, mine is: /opt/qtsdk-2009.03/
    1
    2
    3
    4
    5
    6
    
    cd /opt/qtsdk-2009.03/
    cd qt/src/plugins/sqldrivers/mysql/
    # Replace all the path based on your computer environment. 
    # Make sure 'qmake' can be run from anywhere or you'd have to specify the full path for it.
    qmake -o Makefile "INCLUDEPATH+=/usr/include/mysql" "LIBS+=-L/usr/lib/mysql -lmysqlclient" mysql.pro
    make
  6. You should have new files created for you:
    Makefile
    README
    libqsqlmysql.so*
    main.cpp
    main.o
    moc_qsql_mysql.cpp
    moc_qsql_mysql.o
    mysql.pro
    qsql_mysql.moc
    qsql_mysql.o
  7. Copy MySQL plugin to your Qt’s plugins directory,
    cp libqsqlmysql.so /opt/qtsdk-2009.03/qt/plugins/sqldrivers
  8. Create new project and put these codes to test your new plugin
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    #include <QCoreApplication>
    #include <QtSql>
     
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
     
        qDebug() << QSqlDatabase::drivers();
     
        return a.exec();
    }

    You’ll get these outputs showing that your Qt has supports for MySQL

    ("QSQLITE", "QMYSQL3", "QMYSQL")
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • PDF
  • Print
  • Reddit
  • Slashdot
  • Technorati
  • Twitter

Related Posts

Written by amree

July 22nd, 2009 at 3:21 pm

Posted in programming

Tagged with , , ,

5 Responses to 'How to enable MySQL support in Qt SDK for Linux'

Subscribe to comments with RSS or TrackBack to 'How to enable MySQL support in Qt SDK for Linux'.

  1. Hello,

    I tried the exact steps above but qt still shows just (“QSQLITE”) driver and none others.

    I am running opensuse 11 and qtsdk-2009-03.

    NihalNo Gravatar

    20 Aug 09 at 10:55 PM

  2. Hi, I’m using windows, and I can compile and build the dll’s but when I copy the dlls to C:\Qt\2009.03\qt\plugins\sqldrivers and compile again the project the “QSqlDatabase::drivers();” does not show the QMYSQL

    SalvadorNo Gravatar

    27 Aug 09 at 09:26 AM

  3. @Nihal

    I’ll try these steps again on my new Slackware 13.0 rig.

    UPDATE: I’ve just tested this on my new installed Slackware 13.0 and it still works. You should try checking if you’ve specified the correct directory and followed the steps correctly. Good luck!

    @Salvador

    I guess you’ve managed to solve it, congratulation :)

    amreeNo Gravatar

    30 Aug 09 at 06:27 PM

  4. Thanks! These instructions worked great for me with a new install of Linux Mint. However, first I had to modify Aptitude to show source packages, install the headers & libs for mysql (they showed up in the same place as described above).

    EdNo Gravatar

    15 Jun 10 at 01:02 PM

  5. @Ed

    Thanks for the comment, I’m sure it will be very helpful for other Mint users

    amreeNo Gravatar

    15 Jun 10 at 05:14 PM

Leave a Reply