How to create Qt 6.5 mysql driver with cmake?
-
@thecodemonkey Sir, I extracted those in my project file is it, ok? (But it didn't work)
And did you mean any of the folder in Qt by "subdirectory "?Also, this code also got me the same error.
-
-
@Saad02 there are two possibilites, both should work:
- in Qt installation dir. For MinGW that would be something like C:\Qt\6.5.1\mingw_64\plugins\sqldrivers
- a subdirectory in your project build path (where the compiler creates the exe file of your project), like this:
libmysql.dll must be accessible, too. So either copy it to your project build path, or some other path that is added to your PATH environment variable
-
@thecodemonkey Sir, copied all files in release and debug, qmysql.lib in C:\Qt\6.5.1\mingw_64\plugins\sqldrivers and also added the folder in environment. But it didn't work.
-
@Saad02 said in How to create Qt 6.5 mysql driver with cmake?:
But it didn't work.
Please be more specific
-
Also, added "qsqlmysql.dll_Qt_SQL_driver_6.5.1_MinGW_11.2.0_64-bit" folder in environment variables' system variables' path.
I have nothing to hide :) -
@thecodemonkey Sir, I am providing you the qt creator messages.
Application Output:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMARIADB QMYSQL QODBC QPSQLCompile Output:
C:/Qt/Tools/mingw1120_64/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'C:/Users/Saad/Documents/qt c++/build-database-Desktop_Qt_6_5_1_MinGW_64_bit-Release'
C:\Qt\6.5.1\mingw_64\bin\uic.exe ..\database\mainwindow.ui -o ui_mainwindow.h
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../database -I. -IC:/Qt/6.5.1/mingw_64/include -IC:/Qt/6.5.1/mingw_64/include/QtWidgets -IC:/Qt/6.5.1/mingw_64/include/QtGui -IC:/Qt/6.5.1/mingw_64/include/QtSql -IC:/Qt/6.5.1/mingw_64/include/QtCore -Irelease -I. -I/include -IC:/Qt/6.5.1/mingw_64/mkspecs/win32-g++ -o release\main.o ..\database\main.cpp
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../database -I. -IC:/Qt/6.5.1/mingw_64/include -IC:/Qt/6.5.1/mingw_64/include/QtWidgets -IC:/Qt/6.5.1/mingw_64/include/QtGui -IC:/Qt/6.5.1/mingw_64/include/QtSql -IC:/Qt/6.5.1/mingw_64/include/QtCore -Irelease -I. -I/include -IC:/Qt/6.5.1/mingw_64/mkspecs/win32-g++ -o release\mainwindow.o ..\database\mainwindow.cpp
C:\Qt\6.5.1\mingw_64\bin\moc.exe -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 --include "C:/Users/Saad/Documents/qt c++/build-database-Desktop_Qt_6_5_1_MinGW_64_bit-Release/release/moc_predefs.h" -IC:/Qt/6.5.1/mingw_64/mkspecs/win32-g++ -I"C:/Users/Saad/Documents/qt c++/database" -IC:/Qt/6.5.1/mingw_64/include -IC:/Qt/6.5.1/mingw_64/include/QtWidgets -IC:/Qt/6.5.1/mingw_64/include/QtGui -IC:/Qt/6.5.1/mingw_64/include/QtSql -IC:/Qt/6.5.1/mingw_64/include/QtCore -I. -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++ -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/x86_64-w64-mingw32 -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/backward -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include -IC:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include-fixed -IC:/Qt/Tools/mingw1120_64/x86_64-w64-mingw32/include ..\database\mainwindow.h -o release\moc_mainwindow.cpp
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../database -I. -IC:/Qt/6.5.1/mingw_64/include -IC:/Qt/6.5.1/mingw_64/include/QtWidgets -IC:/Qt/6.5.1/mingw_64/include/QtGui -IC:/Qt/6.5.1/mingw_64/include/QtSql -IC:/Qt/6.5.1/mingw_64/include/QtCore -Irelease -I. -I/include -IC:/Qt/6.5.1/mingw_64/mkspecs/win32-g++ -o release\moc_mainwindow.o release\moc_mainwindow.cpp
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release\database.exe release/main.o release/mainwindow.o release/moc_mainwindow.o C:\Qt\6.5.1\mingw_64\lib\libQt6Widgets.a C:\Qt\6.5.1\mingw_64\lib\libQt6Gui.a C:\Qt\6.5.1\mingw_64\lib\libQt6Sql.a C:\Qt\6.5.1\mingw_64\lib\libQt6Core.a -lmingw32 C:\Qt\6.5.1\mingw_64\lib\libQt6EntryPoint.a -lshell32
mingw32-make[1]: Leaving directory 'C:/Users/Saad/Documents/qt c++/build-database-Desktop_Qt_6_5_1_MinGW_64_bit-Release'
17:03:21: The process "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" exited normally.
17:03:21: Elapsed time: 00:16. -
@thecodemonkey Nothing changed. I got the same output. Do I have to somewhere else except Qt Creator?
-
@Saad02 said in How to create Qt 6.5 mysql driver with cmake?:
Do I have to somewhere else except Qt Creator?
No, you just need to do it properly. You need to set QT_DEBUG_PLUGINS=1 in Run settings of your project in QtCreator.
-
@jsulm Sir, you mean that file with ".pro" extension right?
database.pro:
QT += core gui sqlgreaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
QT_DEBUG_PLUGINS=1You can make your code fail to compile if it uses deprecated APIs.
In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES +=
main.cpp
mainwindow.cppHEADERS +=
mainwindow.hFORMS +=
mainwindow.uiDefault rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += targetNothing changed!
-
@Saad02 said in How to create Qt 6.5 mysql driver with cmake?:
you mean that file with ".pro" extension right?
No, I did not say a single word about the pro file.
You were asked to set QT_DEBUG_PLUGINS anvironment variable to 1 before starting your application.
You can set it in QtCreator if you go to "Projects/Build & Run/Run/Run Environment". -
@Saad02 said in How to create Qt 6.5 mysql driver with cmake?:
I don't have "run environment" in run
Of course you have, you just need to look bellow the part you posted, really...
-
@jsulm Sir, the red marked one showing me my system variables, not run environment variable.
And this is the rest-
Here is all I have in "run".
By the way, the internet connection in our local is currently unstable. Can it be the reason for that driver not to load? -
@Saad02
It seems to clearly show your Run environment, and that by default is the same as your System environment.You have been asked to add a
QT_DEBUG_PLUGINS
environment variable into the Run environment, so do so.Or, just run your executable from a terminal shell and add the environment variable there.
-
@JonB Done and nothing much happened.
Application Output:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMARIADB QMYSQL QODBC QPSQLCompile Output:
18:27:06: Running steps for project database...
18:27:06: Starting: "C:\Qt\6.5.1\mingw_64\bin\qmake.exe" "C:\Users\Saad\Documents\qt c++\database\database.pro" -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug"
18:27:10: The process "C:\Qt\6.5.1\mingw_64\bin\qmake.exe" exited normally.
18:27:10: Starting: "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" -f "C:/Users/Saad/Documents/qt c++/build-database-Desktop_Qt_6_5_1_MinGW_64_bit-Debug/Makefile" qmake_all
mingw32-make: Nothing to be done for 'qmake_all'.
18:27:10: The process "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" exited normally.
18:27:10: Starting: "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" -j4
C:/Qt/Tools/mingw1120_64/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/Saad/Documents/qt c++/build-database-Desktop_Qt_6_5_1_MinGW_64_bit-Debug'
mingw32-make[1]: Nothing to be done for 'first'.
mingw32-make[1]: Leaving directory 'C:/Users/Saad/Documents/qt c++/build-database-Desktop_Qt_6_5_1_MinGW_64_bit-Debug'
18:27:11: The process "C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe" exited normally.
18:27:11: Elapsed time: 00:05.