How to deploy QSQL plugins
-
On my dev machines I can run applications that uses SQL connections:
$ ls -l Qt/6.2.0/gcc_64/plugins/sqldrivers/libqsql* -rwxr-xr-x 1 mark mark 1363192 set 24 18:30 Qt/6.2.0/gcc_64/plugins/sqldrivers/libqsqlite.so -rwxr-xr-x 1 mark mark 86608 set 24 18:30 Qt/6.2.0/gcc_64/plugins/sqldrivers/libqsqlmysql.so -rwxr-xr-x 1 mark mark 128176 set 24 18:30 Qt/6.2.0/gcc_64/plugins/sqldrivers/libqsqlodbc.so -rwxr-xr-x 1 mark mark 98800 set 24 18:30 Qt/6.2.0/gcc_64/plugins/sqldrivers/libqsqlpsql.so
Now I want to deploy the application on a remote target. Both machines run Ubuntu 20.04.
In the target machine I have:- Qt libraries in
/home/user/qt6
(LD_LIBRARY_PATH
is set to this directory) - app binary in
/home/user/bin
Reading the docs I tried to:
- place the above files in
/home/user/bin
(application directory) export QT_PLUGIN_PATH=/home/user/bin/
But in both cases I get:
$ ./app QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers:
Here the test code that runs fine on the dev machine:
#include <QCoreApplication> #include <QSqlDatabase> #include <QSqlQuery> #include <QSqlError> #include <QObject> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("192.168.1.28"); db.setPort(3306); db.setDatabaseName("<database>"); db.setUserName("<username>"); db.setPassword("<password>"); qDebug() << db.open(); return a.exec(); }
Is there anything else I need to deploy on the target machine?
- Qt libraries in
-
@Mark81 said in How to deploy QSQL plugins:
Reading the docs I tried to:
place the above files in /home/user/bin (application directory)
export QT_PLUGIN_PATH=/home/user/bin/You should take a look at https://doc.qt.io/qt-6/linux-deployment.html
Qt aoolication expect specific directory structure (plug-ins go to plugins subfolder for example). -
@jsulm
Ok, I if understood correcly this is the key:When looking for plugins, the application searches in a plugins subdirectory inside the directory of the application executable.
So this is the new directory structure:
$ tree . . └── bin ├── plugins │ ├── libqsqlite.so │ ├── libqsqlmysql.so │ ├── libqsqlodbc.so │ └── libqsqlpsql.so └── app
Same error.
Also:An alternative to putting the plugins in the plugins subdirectory is to add a custom search path when you start your application using QApplication::addLibraryPath() or QApplication::setLibraryPaths().
QCoreApplication a(argc, argv); QCoreApplication::setLibraryPaths(QStringList() << "/home/user/bin/plugins");
leads to the same error.
Where is my mistake now?
-
I also checked the dependencies of the mysql plugin are there:
$ ldd libqsqlmysql.so linux-vdso.so.1 (0x00007ffd755cb000) libmysqlclient.so.21 => /lib/x86_64-linux-gnu/libmysqlclient.so.21 (0x00007fb188a16000) libQt6Sql.so.6 => /home/user/qt6/libQt6Sql.so.6 (0x00007fb1889c9000) libQt6Core.so.6 => /home/user/qt6/libQt6Core.so.6 (0x00007fb18839b000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb188378000) libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fb188196000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb188047000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb18802a000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb187e38000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb187e32000) libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fb187e16000) libssl.so.1.1 => /lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007fb187d83000) libcrypto.so.1.1 => /lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007fb187aad000) libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fb187a8f000) /lib64/ld-linux-x86-64.so.2 (0x00007fb189175000) libicui18n.so.56 => /home/user/qt6/libicui18n.so.56 (0x00007fb1875f6000) libicuuc.so.56 => /home/user/qt6/libicuuc.so.56 (0x00007fb18723e000) libicudata.so.56 => /home/user/qt6/libicudata.so.56 (0x00007fb18585b000) libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fb185732000) libgthread-2.0.so.0 => /lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fb18572d000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb185720000) libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fb1856ad000)
-
@Mark81 said in How to deploy QSQL plugins:
QCoreApplication::setLibraryPaths(QStringList() << "/home/user/bin/plugins");
I think this line should be above the other one.
See also https://doc.qt.io/qt-6/windows-deployment.html#application-dependencies
"Similar to the platform plugin, each type of plugin must be located within a specific subdirectory (such as printsupport, imageformats or sqldrivers) within your distribution directory"
So, it should be YOUR_APP_FOLDER/plugins/sqldrivers (basically same directory structure as in your Qt installation). -
@jsulm said in How to deploy QSQL plugins:
Aaaarghhh, it's too fragmented the documentation :-) It would be better if they reported all the information in the same place!
Anyway:$ tree . . └── bin ├── plugins │ └── sqldrivers │ ├── libqsqlite.so │ ├── libqsqlmysql.so │ ├── libqsqlodbc.so │ └── libqsqlpsql.so └── app
Leads to the very same error.
Furthermore:QPluginLoader loader; loader.setFileName("/home/user/bin/plugins/sqldrivers/libqsqlmysql.so"); qDebug() << loader.load(); qDebug() << loader.errorString();
outputs:
true
"Unknown error"BUT:
QCoreApplication::setLibraryPaths(QStringList() << "/home/user/bin/plugins");
did the trick!
I still don't understand:- why
QPluginLoader
told me it loaded the plugin correctly while after a while the application said the plugin were not loaded - why I have to specify with
setLibraryPaths
the expected path for plugins (app path/plugins) ?
- why
-
@Mark81 said in How to deploy QSQL plugins:
why QPluginLoader told me it loaded the plugin correctly while after a while the application said the plugin were not loaded
Because you used absolute path to the plug-in.
I'm not sure why the plug-ins are not found, but you can also provide https://doc.qt.io/qt-6/qt-conf.html file where you specify all needed paths.