DEV Community

Cover image for How I Build a MySql plugin for QT5 (Windows, MinGW32)
kiran thilak
kiran thilak

Posted on

How I Build a MySql plugin for QT5 (Windows, MinGW32)

  1. Download MySql C Connector v6.1.

    Download the MySql Installer from:
    https://dev.mysql.com/downloads/installer/
    Install C Connector 6.1 (Note the location we will need it later)

  2. Getting QT Source Ready

    To build a plugin for QT u need to get its source. You can install it from Maintenance Tool or manually get it from github repository.

  3. Building Plugin

    1. Open MinGW CMD (Windows -> Start Menu -> Programs -> Qt 5.13.1 -> 5.13.1-> MinGW 7.3.0 (32-bit) -> Qt 5.13.1 (MinGW 7.3.0 32-bit) )
    2. cd to sqldrivers path in qt source
    cd D:\\QT\\Qt5.13.1\\5.13.1\\Src\\qtbase\\src\\plugins\\sqldrivers
    
    1. Run qmake here. qmake sqldrivers.pro (to create qtsqldrivers-config.pri )
    2. cd to mysql.
    cd D:\\QT\\Qt5.13.1\\5.13.1\\Src\\qtbase\\src\\plugins\\sqldrivers\\mysql
    
    1. Run qmake here. qmake mysql.pro
  4. Add the plugin to the list

    Once successfully build you will find qsqlmysql.dll and qsqlmysqld.dll in
    the following location
    D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers

    Copy both qsqlmysql.dll and qsqlmysqld.dll and place them in the compiler’s
    plugin directory
    D:\QT\Qt5.13.1\5.13.1\mingw73_32\plugins\sqldrivers

Error in Building?

  1. Library 'mysql' is not defined.

    In file cd
    D:\QT\Qt5.13.1\5.13.1\Src\qtbase\src\plugins\sqldrivers\mysql\mysql.pro

    Commend the line QMAKE_USE += mysql

  2. Adding Library path and Include path.

    Add the following to mysql.pro at end

    LIBS += -L'C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/lib/'
    -llibmysql
    
    INCLUDEPATH += 'C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/include'
    
    DEPENDPATH += 'C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/include'
    
  3. QSqlDatabase: QMYSQL driver not loaded

    Add the .dll files from C:/Program Files (x86)/MySQL/MySQL Connector C 6.1/lib to D:\QT\Qt5.13.1\5.13.1\mingw73_32\bin

Top comments (0)