QT Deploy QPSQL Plugin
-
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 .
-
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"): ...
-
@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.
-
@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. -
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"): ...
-
@hskoglund said in QT Deploy QPSQL Plugin:
DB = QSqlDatabase::addDatabase("QPSQL"):
IT WAS THAT, THANK YOU VERY MUCH!!
-
@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 theQCoreApplication
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 aQSqlDatabase
, and not to keep even a member variableQSqlDatabase
around. You don't need it.