Sohag Developer PostgreSQL Database Applications

Build Powerful Robust Database Applications

Qt MySQL Driver Not Loaded

Wed, 07/18/2018 - 18:08 - amr

Finally I solved the problem and now I can connect to MariaDb from Qt on fedora linux OS.
Fedora 28, MariaDB-10.2.16 and Qt 5.9.6
After searching for long time I didn't find any solutions, I decided to build the qt mysql driver although there was pre-built driver shipped with Qt 5 .
It works after replacing the pre-built Qt MySQL driver with one I've built.

Instructions to build the mysql driver.

For me I've Qt installed on the following path /opt/Qt5.9.6 so don't forget to change the paths according to your installation.
Also make sure that you have the package mariadb-devel or mysql-devel (this package includes header files used to compile the driver) installed according to the database server you have installed on your system, If they are not installed you can install it by the following command as super user


dnf install mariadb-devel

Building the Qt MySQL driver


cd /opt/Qt5.9.6/5.9.6/Src/qtbase/src/plugins/sqldrivers/
/opt/Qt5.9.6/5.9.6/gcc_64/bin/qmake -- MYSQL_PREFIX=/usr/include/mysql
make sub-mysql

After building the driver back the Qt pre-built libqsqlmysql.so up by the following command you may need it later.


mv /opt/Qt5.9.6/5.9.6/gcc_64/plugins/sqldrivers/libqsqlmysql.so /opt/Qt5.9.6/5.9.6/gcc_64/plugins/sqldrivers/libqsqlmysql.so.old 

And the final step is copy our mysql driver to Qt plugin folder by the following command.


cp /opt/Qt5.9.6/5.9.6/Src/qtbase/src/plugins/sqldrivers/plugins/sqldrivers/libqsqlmysql.so /opt/Qt5.9.6/5.9.6/gcc_64/plugins/sqldrivers/

Now run your application and connect to mariadb (MySql).
Also I've the same issue on windows I'll try to build the driver on windows and I'll add the instructions later.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.