Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. How to deploy QSQL plugins

How to deploy QSQL plugins

Scheduled Pinned Locked Moved Solved Installation and Deployment
7 Posts 2 Posters 565 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark81
    wrote on 9 Nov 2021, 10:23 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 9 Nov 2021, 10:44 last edited by
      #2

      @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).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mark81
        wrote on 9 Nov 2021, 10:53 last edited by
        #3

        @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?

        J 1 Reply Last reply 9 Nov 2021, 11:01
        0
        • M Offline
          M Offline
          Mark81
          wrote on 9 Nov 2021, 10:56 last edited by
          #4

          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)
          
          1 Reply Last reply
          0
          • M Mark81
            9 Nov 2021, 10:53

            @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?

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 9 Nov 2021, 11:01 last edited by
            #5

            @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).

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Mark81
              wrote on 9 Nov 2021, 11:16 last edited by Mark81 11 Sept 2021, 11:17
              #6

              @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:

              1. why QPluginLoader told me it loaded the plugin correctly while after a while the application said the plugin were not loaded
              2. why I have to specify with setLibraryPaths the expected path for plugins (app path/plugins) ?
              J 1 Reply Last reply 9 Nov 2021, 12:32
              0
              • M Mark81
                9 Nov 2021, 11:16

                @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:

                1. why QPluginLoader told me it loaded the plugin correctly while after a while the application said the plugin were not loaded
                2. why I have to specify with setLibraryPaths the expected path for plugins (app path/plugins) ?
                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 9 Nov 2021, 12:32 last edited by
                #7

                @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.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                1/7

                9 Nov 2021, 10:23

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved