QMYSQL driver available but not loaded

How to load qmysql driver in Qt? I have the following code that gives the following results:

 ("QSQLITE", "QMYSQL", "QMYSQL3") QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 

Any suggestions for downloading?

+4
source share
8 answers

ok it worked, just copying the sqldrivers folder to my debug folder, and it worked!

+2
source

We must first check our driver

 $ cd /opt/Qt5.2.1/5.2.1/gcc_64/plugins/sqldrivers 

then we can find some files

Use the command below to test the library

 $ ldd libqsqlmysql.so 

if you find the libmysqlclient_r.so.16 => not found problem, it could be a library dependency problem.

After a little research on the Internet, it would be easy.

 $ cd /usr/lib/x86_64-linux-gnu 

if you find libmysqlclient_r.so.18 ,

 $ cp libmysqlclient_r.so.18 libmysqlclient_r.so.16 
+6
source

You can try to diagnose the problem with strace - it looks like the QMYSQL driver may require some runtime library dependencies to work.

+2
source

On Windows (see directory structure):

 the_qt_app.exe libmysql.dll sqldrivers/qsqlmysql4.dll 
+2
source

You can use QPluginLoader to get the best error message.

When I had the same problem with the MySQL driver, the message was like "The version was compiled with parameters other than this version of Qt."

It seemed that the Qt sources shipped with the Qt SDK at that time were not compatible with its binary files.

After loading Qt sources and compiling my own version of Qt and the MySQL driver, the problem disappeared.

EDIT: some sample code.

 QPluginLoader loader; loader.setFileName("/Users/niklaswulf/QtSDK/Qt/4.8.4/plugins/sqldrivers/libqsqlite_debug.dylib"); qDebug() << loader.load(); qDebug() << loader.errorString(); loader.setFileName("/Users/niklaswulf/QtSDK/Qt/5.0.1/5.0.1/clang_64/plugins/sqldrivers/libqsqlite_debug.dylib"); qDebug() << loader.load(); qDebug() << loader.errorString(); 

When compiling against 5.0.1, this is the result:

 false "The file '/Users/niklaswulf/QtSDK/Qt/4.8.4/plugins/sqldrivers/libqsqlite_debug.dylib' is not a valid Qt plugin." true "Unknown error" 

I also found an old post:

 The plugin '/path/to/some/libqsqlmysql.dylib' uses incompatible Qt library. Expected build key "macosx macx-cocoa g++-4 full-config", got "macosx macx-cocoa g++-4 no-pkg-config" 
+1
source

Here are a couple of very good links on this issue:

Enjoy, Peyman

0
source
 QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 

The same issues I encountered in Fedora20 (64-bit) with Qt-5.2.0, and then follow these steps:

 $ cd /opt/Qt5.2.0/5.2.0/gcc_64/plugins/sqldrivers $ ls libqsqlite.so libqsqlmysql.so 

Use the command below to check library dependency:

 $ ldd libqsqlmysql.so 

I find the problem:

 libmysqlclient_r.so.16 => not found 

This may be a library dependency problem. therefore solve this problem:

Link library file:

  $ ln -s libmysqlclient_r.so.16.0.0 libmysqlclient_r.so 

and again:

 $ ln -s libmysqlclient_r.so.16.0.0 libmysqlclient_r.so.16 

Now his work is for me. All the best

0
source

My answer:

 QSqlDatabase db(QSqlDatabase::addDatabase("QMYSQL")); db.setDatabaseName("dbname"); db.setHostName("localhost"); db.setUserName("usernm"); db.setPassword("password"); if (db.open()) { qDebug() << "SUCCESS!"; db.close(); } 
-2
source

All Articles