0

I'm running QT Creator on Windows 10 and when I want to use MySQL, then it says.

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: 

It's missing drivers.

I have:

  • MySQL worksbench
  • MySQL server
  • MySQL connector/C++
  • And the whole MySQL package
  • Deployed on Windows x64

So why does this not work?

euraad
  • 2,467
  • 5
  • 30
  • 51
  • 1
    You need to compile the QMYSQL plugin using the Qt sources – drescherjm Aug 10 '21 at 22:10
  • @drescherjm Yes. But how can I do that? I'm reading here, but I don't know where to look at https://doc.qt.io/qt-6/sql-driver.html – euraad Aug 10 '21 at 22:20
  • 1
    I believe you need to download the source code for your version of Qt you have installed. In the source code there is the configure file that the documentation talks about. – drescherjm Aug 10 '21 at 22:27
  • @drescherjm But isn't there any easier way? I have installed QT creator and made a project. – euraad Aug 10 '21 at 22:31
  • 1
    You may be able to download the plugin however I am not sure. – drescherjm Aug 10 '21 at 22:33
  • 1
    Here is some other building links I found: [https://dev.to/f1r361rd/how-i-build-a-mysql-plugin-for-qt5-windows-mingw32-2kim](https://dev.to/f1r361rd/how-i-build-a-mysql-plugin-for-qt5-windows-mingw32-2kim) – drescherjm Aug 10 '21 at 22:35
  • 1
    This question shows successfully building the plugin with the command line executed: [https://stackoverflow.com/questions/61322287/qt-qmysql-driver-not-loaded](https://stackoverflow.com/questions/61322287/qt-qmysql-driver-not-loaded) – drescherjm Aug 10 '21 at 22:38
  • @drescherjm Why does this seems so difficult? – euraad Aug 10 '21 at 22:41
  • 1
    It actually looks pretty easy to me compared to other installs. However I have built Qt from source many times (several dozen) over the 13 years I have used it at work. – drescherjm Aug 10 '21 at 22:45
  • @drescherjm So to begin with, I need to open maintance tool? – euraad Aug 10 '21 at 22:50
  • 1
    I think you can install the source code from the online installer. I am not an expert at that part as I only use it when helping someone else or testing Qt-Creator. For my work projects I download the source code .7zip file and build Qt myself. – drescherjm Aug 10 '21 at 22:53
  • @drescherjm Do you think this is a solution? https://doc.qt.io/qt-6/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows – euraad Aug 10 '21 at 23:00
  • 1
    Yes. The plugin dll is built from source in the second step. – drescherjm Aug 10 '21 at 23:10
  • @drescherjm Ok. So in this case my sqldrivers folder is at `C:\QT\6.1.2\mingw81_64\plugins\sqldrivers` and the `lib` folder for Mysql is at `C:\Program Files\MySQL\MySQL Server 8.0\lib` Do I need to write `qt-cmake -G"Ninja"` ? – euraad Aug 10 '21 at 23:14
  • @drescherjm What should I write here `-DCMAKE_INSTALL_PREFIX=\` – euraad Aug 10 '21 at 23:18
  • You know what. I'm quitting using MySQL from now. – euraad Aug 10 '21 at 23:34
  • 1
    There should be a platform folder in the your Qt binaries. I don't have Qt installed from the installer on the current PC so I can't tell you the default folder. – drescherjm Aug 11 '21 at 00:35
  • @drescherjm I'm trying insead to use MySQL Connector/C++ instead directly inside QT. – euraad Aug 11 '21 at 00:36
  • @drescherjm No wait. I will give QT one more chans. I will install QT 5.12.2 instead of latest QT 6.1.12 version – euraad Aug 11 '21 at 01:02
  • @drescherjm When changing to QT5, then I got these now `QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7` :) – euraad Aug 11 '21 at 01:44
  • @drescherjm But running this command `qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"` does not do anyting. Only response with `Usage: qmake [mode] [options] [files]` – euraad Aug 11 '21 at 01:48
  • 1
    You need to run that in the correct folder of your Qt source code for the version of Qt you have installed. I suspect you are not in the correct folder. In the documentation: [https://doc.qt.io/qt-5/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows](https://doc.qt.io/qt-5/sql-driver.html#how-to-build-the-qmysql-plugin-on-windows) it has `cd %QTDIR%\qtbase\src\plugins\sqldrivers` but that requires QTDIR to be set as an environment variable to the location of Qt. You can instead use the path of Qt. – drescherjm Aug 11 '21 at 01:53
  • @drescherjm Is this correct ? `C:\QT\5.12.11\mingw73_64\plugins\sqldrivers>qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"` – euraad Aug 11 '21 at 01:58
  • @drescherjm I don't have `qtbase\src`. Only `%QTDIR%\plugins\sqldrivers` – euraad Aug 11 '21 at 01:59
  • @drescherjm Yes `%QTDIR%` set as an enviroment variable like this https://youtu.be/XiMplRfuFJc?t=301 I can call `qmake` from everywhere – euraad Aug 11 '21 at 01:59
  • 1
    Does `C:\QT\5.12.11\mingw73_64\plugins\sqldrivers` contain a .pro file and source code or is that just dlls and libraries. – drescherjm Aug 11 '21 at 13:47
  • @drescherjm Got it almost working right now. So I open a new question. Se here :) https://stackoverflow.com/questions/68740798/mysql-connector-c-and-mysql-connector-c-does-not-work-with-qt – euraad Aug 11 '21 at 16:49
  • @drescherjm Now I get it working. Thank you so much! – euraad Aug 12 '21 at 00:56

0 Answers0