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. QT Deploy QPSQL Plugin
QtWS25 Last Chance

QT Deploy QPSQL Plugin

Scheduled Pinned Locked Moved Solved Installation and Deployment
c++pluginpostgresqlwindowsdeploy
7 Posts 3 Posters 2.4k 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.
  • T Offline
    T Offline
    thaidy
    wrote on last edited by
    #1

    Hello ,

    I am using QT creator 7.0.0 and I am with a problem that I dont know what to do.
    I have developed my application in the Debug mode and everything was normal when I run and compile.

    Then, I tried do deploy, so I change to the release mode, compile and execute. The program execute normally. Then I go to the release folder created, and copy all dlls of the MingW64/bin and all plugins folders to the release. Then when I try to execute my .exe Its is okay, but the database do not open.
    With the bin files and plugins, i tried to execute directly from Qt and suddently I get this error:

    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers:
    QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
    Failed to connect.

    I really dont know what to do.

    Thanks in advance .

    JonBJ 1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by hskoglund
      #5

      Hi, using static QSqlDatabase instances is a recipe for problems, what happens if you move the declaration into for example your MainWindow.h class:

      ...
      QSqlDatabase DB;
      ...
      

      and then do the addDatabase() call in MainWindow's constructor:

      ui->setupUi(this);
      DB = QSqlDatabase::addDatabase("QPSQL"):
      ...
      
      T 1 Reply Last reply
      2
      • T thaidy

        Hello ,

        I am using QT creator 7.0.0 and I am with a problem that I dont know what to do.
        I have developed my application in the Debug mode and everything was normal when I run and compile.

        Then, I tried do deploy, so I change to the release mode, compile and execute. The program execute normally. Then I go to the release folder created, and copy all dlls of the MingW64/bin and all plugins folders to the release. Then when I try to execute my .exe Its is okay, but the database do not open.
        With the bin files and plugins, i tried to execute directly from Qt and suddently I get this error:

        QSqlDatabase: QPSQL driver not loaded
        QSqlDatabase: available drivers:
        QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
        Failed to connect.

        I really dont know what to do.

        Thanks in advance .

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @thaidy
        Hello and welcome.

        Start by setting environment variable QT_DEBUG_PLUGINS=1 in a Command Prompt and then running your program. It should produce diagnostic output, last few lines should indicate what cannot be found.

        QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins

        That might imply your code is wrong, but may be a result of the previous problem. We will see.

        T 1 Reply Last reply
        0
        • T Offline
          T Offline
          thaidy
          wrote on last edited by thaidy
          #3

          @JonB
          Hello , thank you for the answer .

          The QT_DEBUG_PLUGINS is already like that. But what I really dont understand is why works normally in the Debug mode, but in the release mode, after I include in the folder all the necessary dlls and plugins, the database connection plugin does not even show in the available drivers.

          My compile output is :

          15:59:15: Running steps for project untitled...
          15:59:15: Configuration unchanged, skipping qmake step.
          15:59:15: Starting: "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" -j8
          C:\Qt\6.3.0\mingw_64\bin\qmake.exe -o Makefile ..\untitled\untitled.pro -spec win32-g++ "CONFIG+=qtquickcompiler"
          C:/Qt/Tools/mingw1120_64/bin/mingw32-make -f Makefile.Release
          mingw32-make[1]: Entering directory 'C:/Users/HP/Documents/build-untitled-Desktop_Qt_6_3_0_MinGW_64_bit-Release'
          g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++1z -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SQL_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../untitled -I. -I../../../../Qt/6.3.0/mingw_64/include -I../../../../Qt/6.3.0/mingw_64/include/QtWidgets -I../../../../Qt/6.3.0/mingw_64/include/QtGui -I../../../../Qt/6.3.0/mingw_64/include/QtSql -I../../../../Qt/6.3.0/mingw_64/include/QtCore -Irelease -I. -I/include -I../../../../Qt/6.3.0/mingw_64/mkspecs/win32-g++ -o release\mainwindow.o ..\untitled\mainwindow.cpp
          g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\untitled.exe release/main.o release/mainwindow.o release/orders.o release/qrc_recurso.o release/moc_mainwindow.o release/moc_orders.o C:\Qt\6.3.0\mingw_64\lib\libQt6Widgets.a C:\Qt\6.3.0\mingw_64\lib\libQt6Gui.a C:\Qt\6.3.0\mingw_64\lib\libQt6Sql.a C:\Qt\6.3.0\mingw_64\lib\libQt6Core.a -lmingw32 C:\Qt\6.3.0\mingw_64\lib\libQt6EntryPoint.a -lshell32
          mingw32-make[1]: Leaving directory 'C:/Users/HP/Documents/build-untitled-Desktop_Qt_6_3_0_MinGW_64_bit-Release'
          15:59:27: The process "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" exited normally.
          15:59:27: Elapsed time: 00:12.

          1 Reply Last reply
          0
          • JonBJ JonB

            @thaidy
            Hello and welcome.

            Start by setting environment variable QT_DEBUG_PLUGINS=1 in a Command Prompt and then running your program. It should produce diagnostic output, last few lines should indicate what cannot be found.

            QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins

            That might imply your code is wrong, but may be a result of the previous problem. We will see.

            T Offline
            T Offline
            thaidy
            wrote on last edited by thaidy
            #4

            @JonB

            I used a qDebug() to print in my terminal the drivers in the QList

            First, in the release mode, without the dlls, i have this 3 plugins:

            primeiro.jpg

            After I copy to my release folder the bin dlls the plugins suddenly disappears

            segundo.jpg

            1 Reply Last reply
            0
            • hskoglundH Offline
              hskoglundH Offline
              hskoglund
              wrote on last edited by hskoglund
              #5

              Hi, using static QSqlDatabase instances is a recipe for problems, what happens if you move the declaration into for example your MainWindow.h class:

              ...
              QSqlDatabase DB;
              ...
              

              and then do the addDatabase() call in MainWindow's constructor:

              ui->setupUi(this);
              DB = QSqlDatabase::addDatabase("QPSQL"):
              ...
              
              T 1 Reply Last reply
              2
              • hskoglundH hskoglund

                Hi, using static QSqlDatabase instances is a recipe for problems, what happens if you move the declaration into for example your MainWindow.h class:

                ...
                QSqlDatabase DB;
                ...
                

                and then do the addDatabase() call in MainWindow's constructor:

                ui->setupUi(this);
                DB = QSqlDatabase::addDatabase("QPSQL"):
                ...
                
                T Offline
                T Offline
                thaidy
                wrote on last edited by
                #6

                @hskoglund said in QT Deploy QPSQL Plugin:

                DB = QSqlDatabase::addDatabase("QPSQL"):

                IT WAS THAT, THANK YOU VERY MUCH!!

                JonBJ 1 Reply Last reply
                0
                • T thaidy

                  @hskoglund said in QT Deploy QPSQL Plugin:

                  DB = QSqlDatabase::addDatabase("QPSQL"):

                  IT WAS THAT, THANK YOU VERY MUCH!!

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #7

                  @thaidy said in QT Deploy QPSQL Plugin:

                  @hskoglund said in QT Deploy QPSQL Plugin:

                  what happens if you move the declaration into for example your MainWindow.h class:
                  QSqlDatabase DB;
                  DB = QSqlDatabase::addDatabase("QPSQL"):

                  IT WAS THAT, THANK YOU VERY MUCH!!

                  Glad this has solved problem, certainly better than some static variable.

                  However, this is still not right/advised. Per https://doc.qt.io/qt-5/qsqldatabase.html#details, red box warning:

                  Warning: It is highly recommended that you do not keep a copy of the QSqlDatabase around as a member of a class, as this will prevent the instance from being correctly cleaned up on shutdown. If you need to access an existing QSqlDatabase, it should be accessed with database(). If you chose to have a QSqlDatabase member variable, this needs to be deleted before the QCoreApplication instance is deleted, otherwise it may lead to undefined behavior.

                  Qt asks you to simply call
                  static QSqlDatabase QSqlDatabase::database(const QString &connectionName = QLatin1String(defaultConnection), bool open = true)
                  whenever you need to access a QSqlDatabase, and not to keep even a member variable QSqlDatabase around. You don't need it.

                  1 Reply Last reply
                  0

                  • Login

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