1

Basically when I try to connect to the mysql database i get this error:

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3

I tried to install the drivers, extracting just qtbase from http://download.qt-project.org/official_releases/qt/5.0/5.0.2/single/qt-everywhere-opensource-src-5.0.2.zip and placing it in my Qt directory. I have also followed this guide by inbush: http://www.qtcentre.org/threads/45295-using-mysql-plugin doing this: http://puu.sh/3nyG9.png

inbush says to copy libmysql.dll from C:\mysql\bin to C:\Qt\bin but I didn't find libmysql.dll in bin, but I did find it in lib. So I took that and went to my Qt\bin, and noticed that it was just these files http://puu.sh/3nB5m.png so I thought to place it in Qt\lib instead. I tried re-running my project but it still gave me the same error. My .pro file does indeed have Qt += sql, and I did run qmake afterwards. What am I doing wrong?

1 Answers1

1

Take a look at this post for Qt5, there's also a seperate set of instructions for Qt4 (although somewhat similar).

Qt - How to get|compile Mysql driver

  1. Download a version of MySQL
  2. Download Qt source
  3. Build the MySQL plugin for Qt
  4. Copy the DLL from the MySQL install folder to a Qt folder (see link above)
  5. Copy the DLL you built for the Qt MySQL plugin to a Qt folder

And obviously, when you distribute you'll need to remember to package those DLLs together (always check dependency walker)

Community
  • 1
  • 1
Son-Huy Pham
  • 1,899
  • 18
  • 19
  • Also I want to add that on step 3, you can also move the mysql .lib and .dll (and even the .h includes) files to the same folder as the qtmysqlplugin .pro file for easier building. -- it'll avoid having to pass in those long arguments for the LIBS configuration. It also means you'll need to tweak the .pro file and you can pop it into QtCreator and build like a champ. – Son-Huy Pham Jun 25 '13 at 23:16
  • This is how i build the plugin [link](https://dev.to/f1r361rd/how-i-build-a-mysql-plugin-for-qt5-windows-mingw32-2kim). Thanks for the help. – Kiran Thilak Oct 22 '19 at 04:33