How do I load qmysql
driver in Qt? I have the following code that produces these results:
(\"QSQLITE\", \"QMYSQL\", \"QMYSQL3\")
QSqlDatabase:
On Windows (see as directory structure):
the_qt_app.exe
libmysql.dll
sqldrivers/qsqlmysql4.dll
We should check our driver first
$ cd /opt/Qt5.2.1/5.2.1/gcc_64/plugins/sqldrivers
then we can find some files
Use the command below to check library
$ ldd libqsqlmysql.so
if you find the problem libmysqlclient_r.so.16 => not found
it may be the library-dependency problem.
After I did a little research on the Internet, there is a way 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
You can use QPluginLoader
to get some better error message.
When I had the same problem with the MySQL driver the message was something like "The version was compiled with other options than this Qt version".
It seemed like the Qt sources, that shipped with the Qt SDK at that time, were not compatible with its binaries.
After downloading the Qt sources and compiling my own version of Qt and the MySQL driver, the problem was gone.
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 output:
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 the old message:
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"