Results 1 to 1 of 1

Thread: [SOLVED] How to use MySQL in Qt / plugin not recognized / "module could not be found"

  1. #1
    Join Date
    Jul 2012
    Posts
    1

    Default [SOLVED] How to use MySQL in Qt / plugin not recognized / "module could not be found"

    In order to port a Qt application to Windows, I'm trying to somehow build the MySQL driver (QMYSQL) into the Windows Qt build.
    I built Qt by downloading the sources (4.8.1 in this case), "configure" and "mingw32-make" - but the only database driver that's available in this build is QSLite (QSQLITE).
    So googling around, I found a couple of howtos, like "How to build the MySQL driver for MinGW users", which states a qmake command (after explaining how to rebuild all of Qt, including "reimp", "dlltool" and some sql-related configure options, which didn't really seem to have any effect at all) that contains the MySQL include directory, but not the MySQL lib directory and trying "make" afterwords fails (Qt build dir replaced with $QTDIR):

    g++: error: mysql: No such file or directory
    make[1]: *** [..\..\..\..\plugins\sqldrivers\qsqlmysql4.dll] Error 1
    make[1]: Leaving directory `$QTDIR/src/plugins/sqldrivers/mysql
    '
    make: *** [release] Error 2
    So I ran "make distclean" to clean this up and used another qmake command:
    qmake "INCLUDEPATH+=$MYSQLDIR/include" "LIBS+=-L$MYSQLDIR/lib" mysql.pro
    $MYSQLDIR is the equivalent of "C:\MySQL\MySQL51", $MYSQLDIR/include contains files like mysql.h and $MYSQLDIR/lib contains files like libmysql.a and libmysql.dll (but no "opt" directory, mentioned in step 8). Those files were created by running the "reimp" and "dlltool" commands (link to mingw-utils tarball containing reimp.exe).
    The qmake command created 3 makefiles: Makefile, Makefile.debug and Makefile.release
    I then ran "make" and it successfully created qsqlmysql4.dll in plugins/sqldrivers (and qsqlmysqld4.dll, libqsqlmysql4.a, libqsqlmysqld4.a).
    My Qt application still didn't load the MySQL driver and I didn't know why.

    Then somebody told me to set the environment variable "QT_DEBUG_PLUGINS" to "1" before running my application (unfortunately this isn't mentioned in the howto page, or anywhere else it seems).
    That way I got some helpful information (on standard error) - an error message for every a file and dll file, which looks like this:

    QFactoryLoader::QFactoryLoader() looking at "$QTDIR/plugins/sqldrivers/
    qsqlmysqld4.dll"
    In $QTDIR/plugins/sqldrivers/qsqlmysqld4.dll:
    Plugin uses incompatible Qt library expected build key "Windows mingw release full-config", got "Windows mingw debug full-config"
    Apparently the Qt build I'm using was built in release mode (although debug is supposed to be the default and I'm sure I didn't say "configure -release") and the MySQL plugin was built in debug mode. Since there are targets called "release..." in the new makefiles, I just ran "make clean" and "make release", which created new files that didn't seem to be any different.
    So I ran "make distclean" (removed all 4 mysql a/dll files and the mysql makefiles created by qmake), ran the same qmake command again and then "make release", now I get a new error message:

    QFactoryLoader::QFactoryLoader() looking at "$QTDIR/plugins/sqldrivers/qsqlmysql4.dll"
    QLibraryPrivate::loadPlugin failed on "$QTDIR/plugins/sqldrivers/qsqlmysql4.dll" : "Cannot load library $QTDIR/plugins/sqldrivers/qsqlmysql4.dll: The specified module could not be found."
    "Cannot load library $QTDIR/plugins/sqldrivers/qsqlmysql4.dll: The specified module could not be found."
    could not load
    - What does this mean? The file exists, so I don't know what else it's looking for.
    - Is there a complete documentation page that actually works?

    EDIT/SOLVED:
    I figured it out afterall - $MYSQLDIR/lib/libmysql.dll has to be in the PATH (or in the application directory).
    QSqlDatabase: available drivers: QSQLITE QMYSQL3 QMYSQL
    I'm not going to delete this thread now, maybe it'll help somebody else save some time...
    Last edited by c--; 14th September 2012 at 21:34. Reason: SOLVED

Similar Threads

  1. Qt designer "Module not found"
    By balisingh in forum Qt Quick
    Replies: 0
    Last Post: 27th August 2012, 19:59
  2. Replies: 32
    Last Post: 26th August 2012, 00:10
  3. Replies: 4
    Last Post: 15th July 2012, 03:41
  4. Replies: 1
    Last Post: 18th December 2010, 12:05
  5. "Cannot run program "C:\Qt\4.3.3\bin\qmake": file not found
    By PeteH in forum Installation and Deployment
    Replies: 1
    Last Post: 7th February 2009, 01:48

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.