Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPSQL driver not loaded
QtWS25 Last Chance

QPSQL driver not loaded

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 4 Posters 11.6k 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.
  • I Offline
    I Offline
    ivanicy
    wrote on 3 Feb 2022, 12:47 last edited by
    #1

    Hello!!

    I have an example application that uses a Postgre database.

    I make the connection like this:

    m_pDatabase = new QSqlDatabase(QSqlDatabase::addDatabase("QPSQL"));
    if (m_pDatabase != nullptr) {
            m_pDatabase->setConnectOptions();
            m_pDatabase->setHostName(sServerName);
            m_pDatabase->setDatabaseName(sDatabaseName);
            m_pDatabase->setUserName(sUserName);
            m_pDatabase->setPassword(sPassword);
    }
    
    if (m_pDatabase->open()) {
            return true;
    } else {
            qDebug() << "Error al abrir: " << m_pDatabase->lastError().text();
            return false;
    }
    

    Ok, in my example application it works successfully but, when I copy this code to another application for using the same database it doesn't work:

    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
    

    What could be happening?

    Thank you very much!

    J 1 Reply Last reply 3 Feb 2022, 13:12
    0
    • I ivanicy
      7 Feb 2022, 07:59

      @SGaist I have the same problem. I have removed the execution folder and comment the QMAKE_POST_LINK line, but it doesn't work. I'm a little desperate, but I am very grateful for your time.

      I Offline
      I Offline
      ivanicy
      wrote on 7 Feb 2022, 08:55 last edited by ivanicy 2 Jul 2022, 08:59
      #22

      @ivanicy Well, I have solved the problem. I have copied this dlls from PostgreSQL to the .exe folder:

      libiconv-2.dll
      libintl-8.dll
      libpq.dll

      and... it works!!

      Maybe the problem was that I created this app before I installed the PostgreSQL and the app doesn't integrate the postgre dlls or something like that.

      In any case, copying this dlls solves the problem. Thank you very much guys for your help!!

      1 Reply Last reply
      2
      • I ivanicy
        3 Feb 2022, 12:47

        Hello!!

        I have an example application that uses a Postgre database.

        I make the connection like this:

        m_pDatabase = new QSqlDatabase(QSqlDatabase::addDatabase("QPSQL"));
        if (m_pDatabase != nullptr) {
                m_pDatabase->setConnectOptions();
                m_pDatabase->setHostName(sServerName);
                m_pDatabase->setDatabaseName(sDatabaseName);
                m_pDatabase->setUserName(sUserName);
                m_pDatabase->setPassword(sPassword);
        }
        
        if (m_pDatabase->open()) {
                return true;
        } else {
                qDebug() << "Error al abrir: " << m_pDatabase->lastError().text();
                return false;
        }
        

        Ok, in my example application it works successfully but, when I copy this code to another application for using the same database it doesn't work:

        QSqlDatabase: QPSQL driver not loaded
        QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
        

        What could be happening?

        Thank you very much!

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 3 Feb 2022, 13:12 last edited by
        #2

        @ivanicy said in QPSQL driver not loaded:

        What could be happening?

        Set QT_DEBUG_PLUGINS environment variable to one 1 before starting your application, start your app and check the output (or post it here).

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

        I 1 Reply Last reply 3 Feb 2022, 14:44
        2
        • M Offline
          M Offline
          mchinand
          wrote on 3 Feb 2022, 13:59 last edited by
          #3

          Is your PATH (or the PATH of your Run environment if you're starting them within QtCreator) the same when you run the two applications? The location of the Postgres libraries (from Postgres, not supplied with Qt) needs to be in your PATH.

          1 Reply Last reply
          0
          • J jsulm
            3 Feb 2022, 13:12

            @ivanicy said in QPSQL driver not loaded:

            What could be happening?

            Set QT_DEBUG_PLUGINS environment variable to one 1 before starting your application, start your app and check the output (or post it here).

            I Offline
            I Offline
            ivanicy
            wrote on 3 Feb 2022, 14:44 last edited by
            #4

            @jsulm Ok, this is the output of my example app that works fine:

            Got keys from plugin meta data ("QPSQL7", "QPSQL")
            QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/Ivan/Desktop/Pruebas/DataBase/build-DataBase-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug/debug/sqldrivers" ...
            loaded library "C:/Qt/Qt5.14.2/5.14.2/msvc2017_64/plugins/sqldrivers/qsqlpsqld.dll"
            

            And this is the output for my other app that doesn't work:

            Cannot load library C:\Users\Ivan\Desktop\Proyectos\sw_RedLook_Fix\build-sw_RedLook_Fix-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug\debug\sqldrivers\qsqlpsqld.dll: No se puede encontrar el módulo especificado.
            QLibraryPrivate::loadPlugin failed on "C:/Users/Ivan/Desktop/Proyectos/sw_RedLook_Fix/build-sw_RedLook_Fix-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug/debug/sqldrivers/qsqlpsqld.dll" : "Cannot load library C:\\Users\\Ivan\\Desktop\\Proyectos\\sw_RedLook_Fix\\build-sw_RedLook_Fix-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug\\debug\\sqldrivers\\qsqlpsqld.dll: No se puede encontrar el módulo especificado."
            QSqlDatabase: QPSQL driver not loaded
            QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
            

            Apparently in the first case it is taking the dll from msvc2017 and in the second from the program folder it is not? How can I change it?

            Thank you very much!

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mchinand
              wrote on 3 Feb 2022, 15:06 last edited by
              #5

              You can delete the 'sqldrivers' folder (and any other Qt plugin folders) from your build directory; it should then load from the Qt directory.

              I 1 Reply Last reply 3 Feb 2022, 15:14
              0
              • M mchinand
                3 Feb 2022, 15:06

                You can delete the 'sqldrivers' folder (and any other Qt plugin folders) from your build directory; it should then load from the Qt directory.

                I Offline
                I Offline
                ivanicy
                wrote on 3 Feb 2022, 15:14 last edited by
                #6

                @mchinand It has been created again this folder when I execute and I don't know why.

                M 1 Reply Last reply 3 Feb 2022, 15:19
                0
                • I ivanicy
                  3 Feb 2022, 15:14

                  @mchinand It has been created again this folder when I execute and I don't know why.

                  M Offline
                  M Offline
                  mchinand
                  wrote on 3 Feb 2022, 15:19 last edited by
                  #7

                  Can you post your .pro project file?

                  I 1 Reply Last reply 3 Feb 2022, 15:36
                  0
                  • M mchinand
                    3 Feb 2022, 15:19

                    Can you post your .pro project file?

                    I Offline
                    I Offline
                    ivanicy
                    wrote on 3 Feb 2022, 15:36 last edited by
                    #8

                    @mchinand In .pro file I only add "QT += sql". But I don't why it can't find the qsqlpsqld.dll file. This dll is in the sqldrivers folder. How can I make the QFactoryLoader look in the correct folder?

                    M 1 Reply Last reply 3 Feb 2022, 15:43
                    0
                    • I ivanicy
                      3 Feb 2022, 15:36

                      @mchinand In .pro file I only add "QT += sql". But I don't why it can't find the qsqlpsqld.dll file. This dll is in the sqldrivers folder. How can I make the QFactoryLoader look in the correct folder?

                      M Offline
                      M Offline
                      mchinand
                      wrote on 3 Feb 2022, 15:43 last edited by
                      #9

                      Is there an install or post-build step in your project file?

                      I 1 Reply Last reply 3 Feb 2022, 15:58
                      0
                      • M mchinand
                        3 Feb 2022, 15:43

                        Is there an install or post-build step in your project file?

                        I Offline
                        I Offline
                        ivanicy
                        wrote on 3 Feb 2022, 15:58 last edited by
                        #10
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mchinand
                          wrote on 3 Feb 2022, 16:11 last edited by
                          #11

                          Do you have the postgres Qt plugin in one of the many directories you are copying?

                          I 1 Reply Last reply 3 Feb 2022, 16:16
                          0
                          • M mchinand
                            3 Feb 2022, 16:11

                            Do you have the postgres Qt plugin in one of the many directories you are copying?

                            I Offline
                            I Offline
                            ivanicy
                            wrote on 3 Feb 2022, 16:16 last edited by
                            #12

                            @mchinand I have another clue. I have tried to execute the application from the application folder (out of Qt) and it works...

                            M 1 Reply Last reply 3 Feb 2022, 18:19
                            0
                            • I ivanicy
                              3 Feb 2022, 16:16

                              @mchinand I have another clue. I have tried to execute the application from the application folder (out of Qt) and it works...

                              M Offline
                              M Offline
                              mchinand
                              wrote on 3 Feb 2022, 18:19 last edited by
                              #13

                              When you say 'out of Qt' do you mean not from QtCreator?

                              I 1 Reply Last reply 4 Feb 2022, 07:45
                              0
                              • M mchinand
                                3 Feb 2022, 18:19

                                When you say 'out of Qt' do you mean not from QtCreator?

                                I Offline
                                I Offline
                                ivanicy
                                wrote on 4 Feb 2022, 07:45 last edited by
                                #14

                                @mchinand Yeah, I mean, opening the .exe directly

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 4 Feb 2022, 08:26 last edited by
                                  #15

                                  Hi,

                                  Did you build the plugin both for debug and release ?

                                  Note that the length of your application output with regard to the QPSQL driver messages indicates that you likely did not properly set the QT_DEBUG_PLUGINS environment in Qt Creator. It should be done in the Run part of the Project panel.

                                  You should be swamped with plugin related messages and have something more informative with regard to what happens when the plugin loading fails.

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  I 1 Reply Last reply 4 Feb 2022, 08:37
                                  0
                                  • SGaistS SGaist
                                    4 Feb 2022, 08:26

                                    Hi,

                                    Did you build the plugin both for debug and release ?

                                    Note that the length of your application output with regard to the QPSQL driver messages indicates that you likely did not properly set the QT_DEBUG_PLUGINS environment in Qt Creator. It should be done in the Run part of the Project panel.

                                    You should be swamped with plugin related messages and have something more informative with regard to what happens when the plugin loading fails.

                                    I Offline
                                    I Offline
                                    ivanicy
                                    wrote on 4 Feb 2022, 08:37 last edited by ivanicy 2 Apr 2022, 08:40
                                    #16

                                    @SGaist I have this:

                                    Got keys from plugin meta data ("QPSQL7", "QPSQL")
                                    Cannot load library C:\Users\Ivan\Desktop\Proyectos\sw_RedLook_Fix\build-sw_RedLook_Fix-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug\debug\sqldrivers\qsqlpsqld.dll: No se puede encontrar el módulo especificado.
                                    QLibraryPrivate::loadPlugin failed on "C:/Users/Ivan/Desktop/Proyectos/sw_RedLook_Fix/build-sw_RedLook_Fix-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug/debug/sqldrivers/qsqlpsqld.dll" : "Cannot load library C:\\Users\\Ivan\\Desktop\\Proyectos\\sw_RedLook_Fix\\build-sw_RedLook_Fix-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug\\debug\\sqldrivers\\qsqlpsqld.dll: No se puede encontrar el módulo especificado."
                                    QSqlDatabase: QPSQL driver not loaded
                                    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
                                    Error al abrir:  "Driver not loaded Driver not loaded"
                                    ERROR:  "Driver not loaded Driver not loaded"
                                    

                                    I have two doubts here:

                                    1. ¿Why it couldn't find qsqlpsqld.dll file if the path is correct. I have this dll in sqldrivers folder.

                                    7ed96fa7-fb01-4f97-b1d5-baabf52e0f6f-image.png

                                    1. Why Qt creates this folder there if in my example application it doesn't create anything (and it works correctly)
                                    1 Reply Last reply
                                    0
                                    • SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 4 Feb 2022, 08:46 last edited by
                                      #17

                                      One thing I did not realise directly is that it tries to load them from your application folder.
                                      How did the plugins go there ?
                                      Did you run windeployqt at some point in that folder ?

                                      Did you build the plugins yourself ?

                                      Do you have the PostreSQL .dll contains folder in your PATH environment variable ?

                                      One important thing: all the manipulations of the environment variables should be done within Qt Creator and not at your machine level.

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      I 1 Reply Last reply 4 Feb 2022, 08:54
                                      0
                                      • SGaistS SGaist
                                        4 Feb 2022, 08:46

                                        One thing I did not realise directly is that it tries to load them from your application folder.
                                        How did the plugins go there ?
                                        Did you run windeployqt at some point in that folder ?

                                        Did you build the plugins yourself ?

                                        Do you have the PostreSQL .dll contains folder in your PATH environment variable ?

                                        One important thing: all the manipulations of the environment variables should be done within Qt Creator and not at your machine level.

                                        I Offline
                                        I Offline
                                        ivanicy
                                        wrote on 4 Feb 2022, 08:54 last edited by ivanicy 2 Apr 2022, 08:57
                                        #18

                                        @SGaist I have this in .pro. But I have it before add QT += sql:

                                            isEmpty(TARGET_EXT) {
                                                TARGET_CUSTOM_EXT = .exe
                                            } else {
                                                TARGET_CUSTOM_EXT = $${TARGET_EXT}
                                            }
                                        
                                            DEPLOY_COMMAND = windeployqt
                                        
                                            CONFIG( debug, debug|release ) {
                                                # debug
                                                DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/debug/$${TARGET}$${TARGET_CUSTOM_EXT}))
                                            } else {
                                                # release
                                                DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/release/$${TARGET}$${TARGET_CUSTOM_EXT}))
                                            }
                                        
                                            #Uncomment the following line to help debug the deploy command when running qmake
                                            #warning($${DEPLOY_COMMAND} $${DEPLOY_TARGET})
                                        
                                            QMAKE_POST_LINK = $${DEPLOY_COMMAND} $${DEPLOY_TARGET}
                                        

                                        I do the same thing in both applications, I only add QT += sql

                                        I 1 Reply Last reply 4 Feb 2022, 09:27
                                        0
                                        • I ivanicy
                                          4 Feb 2022, 08:54

                                          @SGaist I have this in .pro. But I have it before add QT += sql:

                                              isEmpty(TARGET_EXT) {
                                                  TARGET_CUSTOM_EXT = .exe
                                              } else {
                                                  TARGET_CUSTOM_EXT = $${TARGET_EXT}
                                              }
                                          
                                              DEPLOY_COMMAND = windeployqt
                                          
                                              CONFIG( debug, debug|release ) {
                                                  # debug
                                                  DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/debug/$${TARGET}$${TARGET_CUSTOM_EXT}))
                                              } else {
                                                  # release
                                                  DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/release/$${TARGET}$${TARGET_CUSTOM_EXT}))
                                              }
                                          
                                              #Uncomment the following line to help debug the deploy command when running qmake
                                              #warning($${DEPLOY_COMMAND} $${DEPLOY_TARGET})
                                          
                                              QMAKE_POST_LINK = $${DEPLOY_COMMAND} $${DEPLOY_TARGET}
                                          

                                          I do the same thing in both applications, I only add QT += sql

                                          I Offline
                                          I Offline
                                          ivanicy
                                          wrote on 4 Feb 2022, 09:27 last edited by
                                          #19

                                          @ivanicy When I open the .exe in the application folder, if the sqldrivers folder exists and has the dll, the application works fine, but I don't know why doesn't work when I execute from Qt.

                                          1 Reply Last reply
                                          0
                                          • SGaistS Offline
                                            SGaistS Offline
                                            SGaist
                                            Lifetime Qt Champion
                                            wrote on 4 Feb 2022, 20:54 last edited by
                                            #20

                                            Nuke your build folder and remove the windeployqt call. Do you still have the problem ?

                                            Interested in AI ? www.idiap.ch
                                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                            I 1 Reply Last reply 7 Feb 2022, 07:59
                                            0

                                            2/22

                                            3 Feb 2022, 13:12

                                            topic:navigator.unread, 20
                                            • Login

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