QSqlDatabase: QMYSQL driver not loaded on Ubuntu 15.04 64bits

筅森魡賤 提交于 2019-11-27 15:52:07

First and foremost, double check that you have the packages containing libssl.so, libcrypto.so and libmysqlclient_r.so installed (looks like you have this last one, it's extremely likely you also have the first two, but just double check).

Then, your problem is that you have those shared objects with a different SONAME, sign that they're binary incompatible with the plugin shipped with Qt, which therefore needs to be recompiled.

Therefore:

  1. install the development versions of the packages found above (libssl-dev, mysql-client-dev or similar).

  2. run the MaintenanceTool from your Qt installation, and be sure to select to install Qt's source code too.

  3. Go in QTDIR/5.6/Src/qtbase/src/plugins/sqldrivers/mysql/.

  4. Run the right qmake, i.e. the one coming from that installation of Qt (not the system wide one or similar). Best way to be sure is providing the full path to it: QTDIR/5.6/gcc_64/bin/qmake.

  5. Run make. Hopefully this will just work™; if it complains about some missing libraries, install them and rerun make.

  6. This should now have produced a new libqsqlmysql.so plugin; overwrite the old one with this new one.

I also have the same problem with Qt5.11.1 and my OS is Ubuntu16.04 and I have resolve the problem by installing libmysqlclient18 from here

https://launchpad.net/ubuntu/xenial/amd64/libmysqlclient18/5.6.25-0ubuntu1

After download run the command from download directory,

sudo dpkg -i libmysqlclient18_5.6.25-0ubuntu1_amd64.deb

IVI

There are two fixes for this issue. First try and locate the qtbase folder located within your qt directory and try run ./configure -plugin-sql-mysql which will activate the driver if they're missing.

If this doesn't solve your issue, I suggest that you double check your code and try running one of the Qt examples which makes a connection to the Sql databases. I.e. modify the example code which connects to a local SQLite database changing the parameter to MySQL. If this example doesn't throw 'Driver not loaded error' then follow the step below.

Make sure you're using the static function of the QSqlDatabase i.e. rather than using

QSqlDatabase *db = new QSqlDatabase(); 
db->addDatabase("QMYSQL");  

you should be doing

QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!