Pikopong

It's all about knowledge

How to enable MySQL support in Qt SDK for Windows

View Comments

  1. Download Qt SDK for Windows at Qt Software and install.
  2. Download MySQL Community Server (MSI Installer) from MySQL and install. Make sure you’ve included C header and necessary lib files during the installation (use Custom Install)
    mysql
  3. Open Qt Command Prompt from the Start Menu

  4. Run these commands, modify it if you install your MySQL at different path. You just have to set the path to your MySQL library since Qt’s paths will be set automatically based on your installation if you use Qt Command Prompt:
    Setting up a MinGW/Qt only environment...
    -- QTDIR set to C:\Qt\2010.02.1\qt
    -- PATH set to C:\Qt\2010.02.1\qt\bin
    -- Adding C:\Qt\2010.02.1\bin to PATH
    -- Adding C:\WINDOWS\System32 to PATH
    -- QMAKESPEC set to win32-g++
    C:\Qt\2010.02.1\qt>set mySQLDIR=C:\PROGRA~1\MySQL\MYSQLS~1.1
    C:\Qt\2010.02.1\qt>cd %QTDIR%\src\plugins\sqldrivers\mysql
    C:\Qt\2010.02.1\qt\src\plugins\sqldrivers\mysql>qmake "INCLUDEPATH+=%mySQLDIR%\include" "LIBS+=%mySQLDIR%\lib\opt\libmysql.lib" -o Makefile mysql.pro
    C:\Qt\2010.02.1\qt\src\plugins\sqldrivers\mysql>mingw32-make
  5. 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();
    }

    Make sure you have QtSql Module in your project configuration file (.pro file)

    QT += sql

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

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

    What matters is that you have QMYSQL in the output.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • PDF
  • Print
  • Reddit
  • Slashdot
  • Technorati
  • Twitter

Related Posts

Written by amree

April 11th, 2010 at 4:38 pm

Posted in programming

Tagged with , , ,

Leave a Reply

blog comments powered by Disqus