When i tried to connect to mysql, there is a error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
"Driver not loaded Driver not loaded"
So i googled it, and i tried :
1.Copy sqldrivers folders to C:QtQt5.8.05.8mingw53_32plugins
2.Copy libmysql.dll to C:QtQt5.8.05.8mingw53_32bin
but the error is still there.
Is there anything i am missing?
asked Mar 8, 2017 at 22:49
2
There are 64 bit and 32 bit versions of libmysql.dll
.
rebuilding the Qt Driver is NOT a must.
With the prebuilt version of Qt5.9.1, you still need to use the 32 bit version, it worked even with the 64 version of MySQL installation. without any rebuild of QT plugins or components.
Download 32 bit MySQL connector here
This was already answered here: medasumanth answer
answered Jul 29, 2017 at 21:13
Mohammad KananMohammad Kanan
4,33510 gold badges22 silver badges45 bronze badges
2
This error generally means that Qt MySQL plugin is fine (as it is listed in available drivers), but you are a missing the MySQL dll (thus preventing the driver to load).
The way to fix it is to place libmysql.dll
somewhere in your PATH, e.g. adding the MySQL installation folder to PATH, or copy libmysql.dll
in the same folder you have your exe in.
answered Mar 9, 2017 at 8:45
Benjamin TBenjamin T
7,97021 silver badges37 bronze badges
If anyone is stupid as i am so that’s for you:
What basically you should do is
- go to https://downloads.mysql.com/archives/c-c/ and download specifically C !!!!!! MysqlConnector;
- place «libmysql.dll» and «libmysql.lib» («mysql-connector-c-6.1.11-winx64.zipmysql-connector-c-6.1.11-winx64lib») into «c:path_to_qtqt_versionyour_compilerbin» for me it looked like «c:Qt5.12.1mingw73_64bin»;
- reload creator and voila your mysql driver is perfectly loaded;
So basically for those who want to understand what happened here:
That «qsqlmysql» plugin is basically a qt interface that uses mysql-C connector methods.
But unfortunately this connector does not distributed with Qt, so you should provide it by yourself.
If you want to distribute your software you should copy «libmysql.dll» into the folder with your «.exe» file.
I hope this will help someone save some time (3hours for me ).
answered Feb 20, 2019 at 1:22
It’s late to answer, but this may be useful for future readers.
When QMYSQL
is available but not loaded, you should find libqsqlmysql.a
and libqsqlmysqld.a
files corresponding to qsqlmysql.dll
and qsqlmysqld.dll
files and copy them (.a files) into «mingw73_xxlib» folder. (xx means 64 or 32)
Note that for project kit 64 bit use MySql 64 bit, and for project kit 32 bit use MySql 32 bit.
Details are available at QT : QSqlDatabase: QMYSQL driver not loaded [WINDOWS]
answered May 21, 2021 at 18:35
- You must rebuild mysql driver.
-
Follow this guide
Note: you need 3 things:
a. qt-opensource-xxx-mingw492-xxx.exe for Qt Creator and Qt command
Prompt.b.qt-everywhere-opensource-src-xxx.zip for Qt source code, needed for mysql.pro file.
c.mysql-connector-c-6.1.10-win32.zip needed for lib and include folder.
answered Jul 8, 2017 at 14:25
dantedante
8242 gold badges10 silver badges22 bronze badges
I had the same problem. I could solved it by following Benjamin T advise. — Windows 10 — python 3.7 — PyQt5 — I copied the libmysql.dll file from the python 3.7/lib/site-packages folder to the Python 3.7 executable folder and everything started working just fine!
answered Feb 11, 2019 at 12:17
ErickErick
3014 silver badges12 bronze badges
This topic has been deleted. Only users with topic management privileges can see it.
Hi All,
I’m trying to make a program that inserts a record into a database. I can’t connect to the database. i get the following error:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
Steps I’ve taken:
install Qt,with the following options:
Installation directory: C:Qt (default)
Components:
QT5.11.1-MinGW5.3.0 32 bit
Qt Creator 4.6.2 CBD Debugger Support (default)
Tools-MinGW5.3.0
Install MySQL, with the following options:
mysql-installer-web-community-8.0.11.0.msi
https://dev.mysql.com/downloads/file/?id=476476
Apply upgrade to the mysql installer: Yes
[x]Accept License terms
Setup type: Developer default (default)
Connector/Python will not be installed
Group replication: standalone (default)
Type and networking: Config type: Development computer (all defaults)
Authentication Method: Strong (default)
MySQL root password: "PassOlyForForumQuestion" (no user accounts)
Windows Server: (all defaults)
MySql Router configuration: (all defaults)
Connect to server: (all defaults)
Create a new Qt program, with the following options:
Qt widgets application
Name: sqlTest
Kit: Desktop Qt 5.11.1 MinGB 32 bit (default)
ClassName: (MainWindow) (default)
Version control: Git
mysql.pro
QT += core gui sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = sqlTest
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES +=
main.cpp
mainwindow.cpp
HEADERS +=
mainwindow.h
FORMS +=
mainwindow.ui
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtSql>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("world");
db.setUserName("root");
db.setPassword("PassOlyForForumQuestion");
bool ok = db.open();
qDebug()<<ok;
}
MainWindow::~MainWindow()
{
delete ui;
}
Program output:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
false
My Versions:
MySQL 8.0.11
Qt 5.10.1
Windows 7 Professional SP1
Whats going wrong?
Cheers,
Cedric
Hi, I think you need to build your mysql driver to use it.
Here there is how could you build this driver
http://doc.qt.io/qt-5/sql-driver.html
or Look this video:
https://www.youtube.com/watch?v=r1TbNjJSlX8
[]s
Thanks Guapo,
I have watched the video, but I did not succeed yet.
I have run the maintenance tool, and added QT5.11.1-source.
In the video, the file c:qtSDK4.8.1srcpluginssqldriversmysqlmysql.pro is used.
On my system it has moved to here: C:Qt5.11.1Srcqtbasesrcpluginssqldriversmysqlmysql.pro
When I open the .pro file, I get the following messages:
Cannot read C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/qtsqldrivers-config.pri: No such file or directory
Project ERROR: Project has no top-level .qmake.conf file.
Error while parsing file C:Qt5.11.1Srcqtbasesrcpluginssqldriversmysqlmysql.pro. Giving up.
Cannot read C:/qtsqldrivers-config.pri: No such file or directory
Cannot read /mkspecs/modules-inst/qt_plugin_qsqlmysql.pri: No such file or directory
C:/Qt/5.11.1/mingw53_32/mkspecs/features/qt_plugin.prf(81): Variable QT_PLUGINS is not defined.
Project ERROR: Library ‘mysql’ is not defined.
I don’t have the file qtsqldrivers-config.pri anywhere below c:qt.
What can I do/check next?
Cheers,
Cedric
Hi All,
I am trying to follow the instructions here, but I’m not successful yet. Configure reports MySql ……………………………. no
I have taken the following steps:
1)Add C:QtToolsmingw530_32bin and C:Qt5.11.1mingw53_32bin to the path
2)Open cmd.exe, and enter the following commands:
cd c:qt5.11.1Srcqtbasesrcpluginssqldrivers
c:Qt5.11.1Srcqtbasesrcpluginssqldrivers>qmake -- MYSQL_INCDIR="c:Program FilesMySQLConnector C++ 1.1libopt"
Running configuration tests...
Checking for DB2 (IBM)... no
Checking for InterBase... no
Checking for MySQL... no
Checking for OCI (Oracle)... no
Checking for ODBC... yes
Checking for PostgreSQL... no
Checking for SQLite (version 2)... no
Checking for TDS (Sybase)... no
Done running configuration tests.
Configure summary:
Qt Sql:
DB2 (IBM) .............................. no
InterBase .............................. no
MySql .................................. no
OCI (Oracle) ........................... no
ODBC ................................... yes
PostgreSQL ............................. no
SQLite2 ................................ no
SQLite ................................. yes
Using system provided SQLite ......... no
TDS (Sybase) ........................... no
Qt is now configured for building. Just run 'mingw32-make'.
Once everything is built, Qt is installed.
You should NOT run 'mingw32-make install'.
Note that this build cannot be deployed to other machines or devices.
Prior to reconfiguration, make sure you remove any leftovers from the previous build.
c:Qt5.11.1Srcqtbasesrcpluginssqldrivers>
What did I miss?
Cheers,
Cedric
hi All,
I also have installed the «MySQL Connector C 6.1», but configure still does not see mySQL:
c:Qt5.11.1Srcqtbasesrcpluginssqldrivers>qmake -- MYSQL_INCDIR="c:Program
FilesMySQLMySQL Connector C 6.1lib"
Running configuration tests...
Done running configuration tests.
Configure summary:
Qt Sql:
DB2 (IBM) .............................. no
InterBase .............................. no
MySql .................................. no
OCI (Oracle) ........................... no
ODBC ................................... yes
PostgreSQL ............................. no
SQLite2 ................................ no
SQLite ................................. yes
Using system provided SQLite ......... no
TDS (Sybase) ........................... no
Qt is now configured for building. Just run 'mingw32-make'.
Once everything is built, Qt is installed.
You should NOT run 'mingw32-make install'.
Note that this build cannot be deployed to other machines or devices.
Prior to reconfiguration, make sure you remove any leftovers from
the previous build.
c:Qt5.11.1Srcqtbasesrcpluginssqldrivers>qmake -- MYSQL_INCDIR="c:Program
FilesMySQLMySQL Connector C 6.1lib"
Info: creating stash file C:Qt5.11.1Srcqtbasesrcpluginssqldrivers.qmake.
stash
Running configuration tests...
Checking for DB2 (IBM)... no
Checking for InterBase... no
Checking for MySQL... no
Checking for OCI (Oracle)... no
Checking for ODBC... yes
Checking for PostgreSQL... no
Checking for SQLite (version 2)... no
Checking for TDS (Sybase)... no
Done running configuration tests.
Configure summary:
Qt Sql:
DB2 (IBM) .............................. no
InterBase .............................. no
MySql .................................. no
OCI (Oracle) ........................... no
ODBC ................................... yes
PostgreSQL ............................. no
SQLite2 ................................ no
SQLite ................................. yes
Using system provided SQLite ......... no
TDS (Sybase) ........................... no
Qt is now configured for building. Just run 'mingw32-make'.
Once everything is built, Qt is installed.
You should NOT run 'mingw32-make install'.
Note that this build cannot be deployed to other machines or devices.
Prior to reconfiguration, make sure you remove any leftovers from
the previous build.
c:Qt5.11.1Srcqtbasesrcpluginssqldrivers>
Cheers,
Cedric
Hi,
Did you check that your MySQL Connector is built for 32bit ?
Hi Sgaist,
My further experiments:
I have downloaded the 32 bit C connector:https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi and installed it. Now I have this directory:
C:Program Files (x86)MySQLMySQL Connector C 6.1lib
Due to the location it installed into, I’m confident that it’s indeed 32 bits. So here we go again I deleted all the generated files from C:Qt5.11.1Srcqtbasesrcpluginssqldrivers
C:Userscedric>cd c:Qt5.11.1Srcqtbasesrcpluginssqldrivers
c:Qt5.11.1Srcqtbasesrcpluginssqldrivers>qmake -- MYSQL_INCDIR="c:Program Files (x86)MySQLMySQL Connector C 6.1lib"
Running configuration tests...
Checking for DB2 (IBM)... no
Checking for InterBase... no
Checking for MySQL... no
Checking for OCI (Oracle)... no
Checking for ODBC... yes
Checking for PostgreSQL... no
Checking for SQLite (version 2)... no
Checking for TDS (Sybase)... no
Done running configuration tests.
My config.log:
Command line: "MYSQL_INCDIR=c:Program Files (x86)MySQLMySQL Connector C 6.1lib"
looking for library db2
Trying source 0 (type inline) of library db2 ...
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsdb2 && C:Qt5.11.1mingw53_32binqmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\openssl\lib C:\Utils\my_sql\mysql-5.6.11-win32\lib C:\Utils\postgresql\pgsql\lib" "INCLUDEPATH += C:\openssl\include C:\Utils\my_sql\mysql-5.6.11-win32\include C:\Utils\postgresql\pgsql\include" "LIBS += -ldb2cli" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/db2
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsdb2 && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make
> del main.o
> Could Not Find C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsdb2main.o
> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:opensslinclude -IC:Utilsmy_sqlmysql-5.6.11-win32include -IC:Utilspostgresqlpgsqlinclude -IC:Qt5.11.1mingw53_32mkspecswin32-g++ -o main.o main.cpp
> main.cpp:2:20: fatal error: sqlcli.h: No such file or directory
> compilation terminated.
> Makefile:415: recipe for target 'main.o' failed
> mingw32-make: *** [main.o] Error 1
=> source failed verification.
Trying source 1 (type inline) of library db2 ...
=> source failed condition '!config.win32'.
test config.sqldrivers.libraries.db2 FAILED
looking for library ibase
Trying source 0 (type inline) of library ibase ...
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsibase && C:Qt5.11.1mingw53_32binqmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\openssl\lib C:\Utils\my_sql\mysql-5.6.11-win32\lib C:\Utils\postgresql\pgsql\lib" "INCLUDEPATH += C:\openssl\include C:\Utils\my_sql\mysql-5.6.11-win32\include C:\Utils\postgresql\pgsql\include" "LIBS += -lgds32_ms" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/ibase
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsibase && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make
> del main.o
> Could Not Find C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsibasemain.o
> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:opensslinclude -IC:Utilsmy_sqlmysql-5.6.11-win32include -IC:Utilspostgresqlpgsqlinclude -IC:Qt5.11.1mingw53_32mkspecswin32-g++ -o main.o main.cpp
> main.cpp:2:19: fatal error: ibase.h: No such file or directory
> compilation terminated.
> Makefile:415: recipe for target 'main.o' failed
> mingw32-make: *** [main.o] Error 1
=> source failed verification.
Trying source 1 (type inline) of library ibase ...
=> source failed condition '!config.win32'.
test config.sqldrivers.libraries.ibase FAILED
looking for library mysql
Trying source 0 (type mysqlConfig) of library mysql ...
mysql_config not found.
=> source produced no result.
Trying source 1 (type mysqlConfig) of library mysql ...
mysql_config not found.
=> source produced no result.
Trying source 2 (type mysqlConfig) of library mysql ...
mysql_config not found.
=> source produced no result.
Trying source 3 (type mysqlConfig) of library mysql ...
mysql_config not found.
=> source produced no result.
Trying source 4 (type inline) of library mysql ...
=> source failed condition '!config.win32'.
Trying source 5 (type inline) of library mysql ...
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsmysql && C:Qt5.11.1mingw53_32binqmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\openssl\lib C:\Utils\my_sql\mysql-5.6.11-win32\lib C:\Utils\postgresql\pgsql\lib" "INCLUDEPATH += C:\openssl\include C:\Utils\my_sql\mysql-5.6.11-win32\include C:\Utils\postgresql\pgsql\include" "LIBS += -llibmysql" "INCLUDEPATH *= "c:\Program Files ^(x86^)\MySQL\MySQL Connector C 6.1\lib"" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/mysql
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsmysql && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make
> del main.o
> Could Not Find C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsmysqlmain.o
> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:opensslinclude -IC:Utilsmy_sqlmysql-5.6.11-win32include -IC:Utilspostgresqlpgsqlinclude -I"c:Program Files (x86)MySQLMySQL Connector C 6.1lib" -IC:Qt5.11.1mingw53_32mkspecswin32-g++ -o main.o main.cpp
> main.cpp:5:19: fatal error: mysql.h: No such file or directory
> compilation terminated.
> Makefile:415: recipe for target 'main.o' failed
> mingw32-make: *** [main.o] Error 1
=> source failed verification.
Trying source 6 (type inline) of library mysql ...
=> source failed condition '!config.win32'.
test config.sqldrivers.libraries.mysql FAILED
looking for library oci
Trying source 0 (type inline) of library oci ...
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsoci && C:Qt5.11.1mingw53_32binqmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\openssl\lib C:\Utils\my_sql\mysql-5.6.11-win32\lib C:\Utils\postgresql\pgsql\lib" "INCLUDEPATH += C:\openssl\include C:\Utils\my_sql\mysql-5.6.11-win32\include C:\Utils\postgresql\pgsql\include" "LIBS += -loci" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/oci
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsoci && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make
> del main.o
> Could Not Find C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsocimain.o
> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:opensslinclude -IC:Utilsmy_sqlmysql-5.6.11-win32include -IC:Utilspostgresqlpgsqlinclude -IC:Qt5.11.1mingw53_32mkspecswin32-g++ -o main.o main.cpp
> main.cpp:2:17: fatal error: oci.h: No such file or directory
> compilation terminated.
> Makefile:415: recipe for target 'main.o' failed
> mingw32-make: *** [main.o] Error 1
=> source failed verification.
Trying source 1 (type inline) of library oci ...
=> source failed condition '!config.win32'.
test config.sqldrivers.libraries.oci FAILED
looking for library odbc
Trying source 0 (type inline) of library odbc ...
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsodbc && C:Qt5.11.1mingw53_32binqmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\openssl\lib C:\Utils\my_sql\mysql-5.6.11-win32\lib C:\Utils\postgresql\pgsql\lib" "INCLUDEPATH += C:\openssl\include C:\Utils\my_sql\mysql-5.6.11-win32\include C:\Utils\postgresql\pgsql\include" "LIBS += -lodbc32" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/odbc
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testsodbc && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make
> del main.o
> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:opensslinclude -IC:Utilsmy_sqlmysql-5.6.11-win32include -IC:Utilspostgresqlpgsqlinclude -IC:Qt5.11.1mingw53_32mkspecswin32-g++ -o main.o main.cpp
> g++ -Wl,-s -Wl,-subsystem,console -mthreads -o odbc.exe main.o -LC:openssllib -LC:Utilsmy_sqlmysql-5.6.11-win32lib -LC:Utilspostgresqlpgsqllib -lodbc32
=> source accepted.
test config.sqldrivers.libraries.odbc succeeded
looking for library psql
Trying source 0 (type pkgConfig) of library psql ...
pkg-config use disabled globally.
=> source produced no result.
Trying source 1 (type psqlConfig) of library psql ...
pg_config not found.
=> source produced no result.
Trying source 2 (type psqlEnv) of library psql ...
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testspsql && C:Qt5.11.1mingw53_32binqmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\openssl\lib C:\Utils\my_sql\mysql-5.6.11-win32\lib C:\Utils\postgresql\pgsql\lib" "INCLUDEPATH += C:\openssl\include C:\Utils\my_sql\mysql-5.6.11-win32\include C:\Utils\postgresql\pgsql\include" "LIBS += -llibpq -lws2_32 -ladvapi32" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/psql
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testspsql && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make
> del main.o
> Could Not Find C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testspsqlmain.o
> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:opensslinclude -IC:Utilsmy_sqlmysql-5.6.11-win32include -IC:Utilspostgresqlpgsqlinclude -IC:Qt5.11.1mingw53_32mkspecswin32-g++ -o main.o main.cpp
> main.cpp:2:22: fatal error: libpq-fe.h: No such file or directory
> compilation terminated.
> Makefile:415: recipe for target 'main.o' failed
> mingw32-make: *** [main.o] Error 1
=> source failed verification.
Trying source 3 (type psqlEnv) of library psql ...
=> source failed condition '!config.win32'.
test config.sqldrivers.libraries.psql FAILED
looking for library sqlite2
Trying source 0 (type inline) of library sqlite2 ...
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testssqlite2 && C:Qt5.11.1mingw53_32binqmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\openssl\lib C:\Utils\my_sql\mysql-5.6.11-win32\lib C:\Utils\postgresql\pgsql\lib" "INCLUDEPATH += C:\openssl\include C:\Utils\my_sql\mysql-5.6.11-win32\include C:\Utils\postgresql\pgsql\include" "LIBS += -lsqlite" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/sqlite2
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testssqlite2 && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make
> del main.o
> Could Not Find C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.testssqlite2main.o
> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:opensslinclude -IC:Utilsmy_sqlmysql-5.6.11-win32include -IC:Utilspostgresqlpgsqlinclude -IC:Qt5.11.1mingw53_32mkspecswin32-g++ -o main.o main.cpp
> main.cpp:2:20: fatal error: sqlite.h: No such file or directory
> compilation terminated.
> Makefile:415: recipe for target 'main.o' failed
> mingw32-make: *** [main.o] Error 1
=> source failed verification.
test config.sqldrivers.libraries.sqlite2 FAILED
looking for library tds
Trying source 0 (type sybaseEnv) of library tds ...
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.teststds && C:Qt5.11.1mingw53_32binqmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\openssl\lib C:\Utils\my_sql\mysql-5.6.11-win32\lib C:\Utils\postgresql\pgsql\lib" "INCLUDEPATH += C:\openssl\include C:\Utils\my_sql\mysql-5.6.11-win32\include C:\Utils\postgresql\pgsql\include" "LIBS += -lNTWDBLIB" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/tds
+ cd /d C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.teststds && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make
> del main.o
> Could Not Find C:Qt5.11.1Srcqtbasesrcpluginssqldriversconfig.teststdsmain.o
> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:opensslinclude -IC:Utilsmy_sqlmysql-5.6.11-win32include -IC:Utilspostgresqlpgsqlinclude -IC:Qt5.11.1mingw53_32mkspecswin32-g++ -o main.o main.cpp
> main.cpp:2:22: fatal error: sybfront.h: No such file or directory
> compilation terminated.
> Makefile:415: recipe for target 'main.o' failed
> mingw32-make: *** [main.o] Error 1
=> source failed verification.
Trying source 1 (type sybaseEnv) of library tds ...
=> source failed condition '!config.win32'.
test config.sqldrivers.libraries.tds FAILED
my config.cache:
cache.platform = win32-g++
cache.xplatform = win32-g++
cache.db2._KEYS_ = result msgs
cache.db2.result = false
cache.db2.msgs = "Trying source 0 (type inline) of library db2 ..." "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\db2 && C:\Qt\5.11.1\mingw53_32\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.6.11-win32\\lib C:\\Utils\\postgresql\\pgsql\\lib" "INCLUDEPATH += C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.6.11-win32\\include C:\\Utils\\postgresql\\pgsql\\include" "LIBS += -ldb2cli" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/db2" "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\db2 && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make" "> del main.o" "> Could Not Find C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\db2\main.o" "> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.6.11-win32\include -IC:\Utils\postgresql\pgsql\include -IC:\Qt\5.11.1\mingw53_32\mkspecs\win32-g++ -o main.o main.cpp" "> main.cpp:2:20: fatal error: sqlcli.h: No such file or directory" "> compilation terminated." "> Makefile:415: recipe for target 'main.o' failed" "> mingw32-make: *** [main.o] Error 1" " => source failed verification." "Trying source 1 (type inline) of library db2 ..." " => source failed condition '!config.win32'."
cache.ibase._KEYS_ = result msgs
cache.ibase.result = false
cache.ibase.msgs = "Trying source 0 (type inline) of library ibase ..." "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\ibase && C:\Qt\5.11.1\mingw53_32\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.6.11-win32\\lib C:\\Utils\\postgresql\\pgsql\\lib" "INCLUDEPATH += C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.6.11-win32\\include C:\\Utils\\postgresql\\pgsql\\include" "LIBS += -lgds32_ms" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/ibase" "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\ibase && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make" "> del main.o" "> Could Not Find C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\ibase\main.o" "> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.6.11-win32\include -IC:\Utils\postgresql\pgsql\include -IC:\Qt\5.11.1\mingw53_32\mkspecs\win32-g++ -o main.o main.cpp" "> main.cpp:2:19: fatal error: ibase.h: No such file or directory" "> compilation terminated." "> Makefile:415: recipe for target 'main.o' failed" "> mingw32-make: *** [main.o] Error 1" " => source failed verification." "Trying source 1 (type inline) of library ibase ..." " => source failed condition '!config.win32'."
cache.mysql._KEYS_ = result msgs
cache.mysql.result = false
cache.mysql.msgs = "Trying source 0 (type mysqlConfig) of library mysql ..." "mysql_config not found." " => source produced no result." "Trying source 1 (type mysqlConfig) of library mysql ..." "mysql_config not found." " => source produced no result." "Trying source 2 (type mysqlConfig) of library mysql ..." "mysql_config not found." " => source produced no result." "Trying source 3 (type mysqlConfig) of library mysql ..." "mysql_config not found." " => source produced no result." "Trying source 4 (type inline) of library mysql ..." " => source failed condition '!config.win32'." "Trying source 5 (type inline) of library mysql ..." "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql && C:\Qt\5.11.1\mingw53_32\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.6.11-win32\\lib C:\\Utils\\postgresql\\pgsql\\lib" "INCLUDEPATH += C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.6.11-win32\\include C:\\Utils\\postgresql\\pgsql\\include" "LIBS += -llibmysql" "INCLUDEPATH *= \"c:\\Program Files ^(x86^)\\MySQL\\MySQL Connector C 6.1\\lib\"" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/mysql" "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make" "> del main.o" "> Could Not Find C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\mysql\main.o" "> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.6.11-win32\include -IC:\Utils\postgresql\pgsql\include -I"c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib" -IC:\Qt\5.11.1\mingw53_32\mkspecs\win32-g++ -o main.o main.cpp" "> main.cpp:5:19: fatal error: mysql.h: No such file or directory" "> compilation terminated." "> Makefile:415: recipe for target 'main.o' failed" "> mingw32-make: *** [main.o] Error 1" " => source failed verification." "Trying source 6 (type inline) of library mysql ..." " => source failed condition '!config.win32'."
cache.oci._KEYS_ = result msgs
cache.oci.result = false
cache.oci.msgs = "Trying source 0 (type inline) of library oci ..." "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\oci && C:\Qt\5.11.1\mingw53_32\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.6.11-win32\\lib C:\\Utils\\postgresql\\pgsql\\lib" "INCLUDEPATH += C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.6.11-win32\\include C:\\Utils\\postgresql\\pgsql\\include" "LIBS += -loci" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/oci" "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\oci && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make" "> del main.o" "> Could Not Find C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\oci\main.o" "> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.6.11-win32\include -IC:\Utils\postgresql\pgsql\include -IC:\Qt\5.11.1\mingw53_32\mkspecs\win32-g++ -o main.o main.cpp" "> main.cpp:2:17: fatal error: oci.h: No such file or directory" "> compilation terminated." "> Makefile:415: recipe for target 'main.o' failed" "> mingw32-make: *** [main.o] Error 1" " => source failed verification." "Trying source 1 (type inline) of library oci ..." " => source failed condition '!config.win32'."
cache.odbc._KEYS_ = result msgs source sources.0.libs sources.0.includedir sources.0.cflags sources.0.version sources.0.export
cache.odbc.result = true
cache.odbc.msgs = "Trying source 0 (type inline) of library odbc ..." "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\odbc && C:\Qt\5.11.1\mingw53_32\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.6.11-win32\\lib C:\\Utils\\postgresql\\pgsql\\lib" "INCLUDEPATH += C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.6.11-win32\\include C:\\Utils\\postgresql\\pgsql\\include" "LIBS += -lodbc32" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/odbc" "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\odbc && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make" "> del main.o" "> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.6.11-win32\include -IC:\Utils\postgresql\pgsql\include -IC:\Qt\5.11.1\mingw53_32\mkspecs\win32-g++ -o main.o main.cpp" "> g++ -Wl,-s -Wl,-subsystem,console -mthreads -o odbc.exe main.o -LC:\openssl\lib -LC:\Utils\my_sql\mysql-5.6.11-win32\lib -LC:\Utils\postgresql\pgsql\lib -lodbc32 " " => source accepted."
cache.odbc.source = 0
cache.odbc.sources.0.libs = -lodbc32
cache.odbc.sources.0.includedir =
cache.odbc.sources.0.cflags =
cache.odbc.sources.0.version =
cache.odbc.sources.0.export =
cache.psql._KEYS_ = result msgs
cache.psql.result = false
cache.psql.msgs = "Trying source 0 (type pkgConfig) of library psql ..." "pkg-config use disabled globally." " => source produced no result." "Trying source 1 (type psqlConfig) of library psql ..." "pg_config not found." " => source produced no result." "Trying source 2 (type psqlEnv) of library psql ..." "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\psql && C:\Qt\5.11.1\mingw53_32\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.6.11-win32\\lib C:\\Utils\\postgresql\\pgsql\\lib" "INCLUDEPATH += C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.6.11-win32\\include C:\\Utils\\postgresql\\pgsql\\include" "LIBS += -llibpq -lws2_32 -ladvapi32" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/psql" "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\psql && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make" "> del main.o" "> Could Not Find C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\psql\main.o" "> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.6.11-win32\include -IC:\Utils\postgresql\pgsql\include -IC:\Qt\5.11.1\mingw53_32\mkspecs\win32-g++ -o main.o main.cpp" "> main.cpp:2:22: fatal error: libpq-fe.h: No such file or directory" "> compilation terminated." "> Makefile:415: recipe for target 'main.o' failed" "> mingw32-make: *** [main.o] Error 1" " => source failed verification." "Trying source 3 (type psqlEnv) of library psql ..." " => source failed condition '!config.win32'."
cache.sqlite2._KEYS_ = result msgs
cache.sqlite2.result = false
cache.sqlite2.msgs = "Trying source 0 (type inline) of library sqlite2 ..." "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\sqlite2 && C:\Qt\5.11.1\mingw53_32\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.6.11-win32\\lib C:\\Utils\\postgresql\\pgsql\\lib" "INCLUDEPATH += C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.6.11-win32\\include C:\\Utils\\postgresql\\pgsql\\include" "LIBS += -lsqlite" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/sqlite2" "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\sqlite2 && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make" "> del main.o" "> Could Not Find C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\sqlite2\main.o" "> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.6.11-win32\include -IC:\Utils\postgresql\pgsql\include -IC:\Qt\5.11.1\mingw53_32\mkspecs\win32-g++ -o main.o main.cpp" "> main.cpp:2:20: fatal error: sqlite.h: No such file or directory" "> compilation terminated." "> Makefile:415: recipe for target 'main.o' failed" "> mingw32-make: *** [main.o] Error 1" " => source failed verification."
cache.tds._KEYS_ = result msgs
cache.tds.result = false
cache.tds.msgs = "Trying source 0 (type sybaseEnv) of library tds ..." "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\tds && C:\Qt\5.11.1\mingw53_32\bin\qmake.exe "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += shared warn_off console single_arch" "QMAKE_LIBDIR += C:\\openssl\\lib C:\\Utils\\my_sql\\mysql-5.6.11-win32\\lib C:\\Utils\\postgresql\\pgsql\\lib" "INCLUDEPATH += C:\\openssl\\include C:\\Utils\\my_sql\\mysql-5.6.11-win32\\include C:\\Utils\\postgresql\\pgsql\\include" "LIBS += -lNTWDBLIB" C:/Qt/5.11.1/Src/qtbase/src/plugins/sqldrivers/config.tests/tds" "+ cd /d C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\tds && set MAKEFLAGS=& mingw32-make clean && set MAKEFLAGS=& mingw32-make" "> del main.o" "> Could Not Find C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\config.tests\tds\main.o" "> g++ -c -fno-keep-inline-dllexport -O2 -std=gnu++11 -w -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -I. -IC:\openssl\include -IC:\Utils\my_sql\mysql-5.6.11-win32\include -IC:\Utils\postgresql\pgsql\include -IC:\Qt\5.11.1\mingw53_32\mkspecs\win32-g++ -o main.o main.cpp" "> main.cpp:2:22: fatal error: sybfront.h: No such file or directory" "> compilation terminated." "> Makefile:415: recipe for target 'main.o' failed" "> mingw32-make: *** [main.o] Error 1" " => source failed verification." "Trying source 1 (type sybaseEnv) of library tds ..." " => source failed condition '!config.win32'."
qtsqldrivers-config.pri
QT.sqldrivers.enabled_features =
QT.sqldrivers.disabled_features =
QT.sqldrivers.QT_CONFIG =
QT.sqldrivers.exports =
QT.sqldrivers_private.enabled_features = sql-odbc sql-sqlite
QT.sqldrivers_private.disabled_features = sql-db2 sql-ibase sql-mysql sql-oci sql-psql sql-sqlite2 sql-tds system-sqlite
QT.sqldrivers_private.libraries = odbc
QMAKE_LIBS_ODBC = -lodbc32
Cheers,
Cedric
Where exactly do you have mysql.h
located on your computer ?
Hi, i have mysql.h at the following locations:
C:Program FilesMySQLMySQL Server 8.0include
C:Program Files (x86)MySQLMySQL Connector C 6.1include
C:Program FilesMySQLMySQL Connector C 6.1include
Cheers,
Cedric
Then why are you using MYSQL_INCDIR="c:Program Files (x86)MySQLMySQL Connector C 6.1lib"
?
It should be include
and not lib
.
Thank you.
I used /lib because it’s in on the instructions on the Qt website: http://doc.qt.io/qt-5/sql-driver.html Can I file a bug report for the instructions on the site?
How to Build the QMYSQL Plugin on Windows
You need to get the MySQL installation files. Run SETUP.EXE and choose "Custom Install". Install the "Libs & Include Files" Module. Build the plugin as follows (here it is assumed that MySQL is installed in C:MySQL):
cd %QTDIR%qtbasesrcpluginssqldrivers
qmake -- MYSQL_INCDIR=C:/MySQL/include "MYSQL_LIBDIR=C:/MYSQL/MySQL Server <version>/lib/opt"
nmake sub-mysql
If you are not using a Microsoft compiler, replace nmake with mingw32-make in the line above.
I’ll test your suggestion shortly.
Cheers,
Cedric
I think you may have misread the documentation.
There are two variables: MYSQL_INCDIR
and MYSQL_LIBDIR
.
I see it now, I indeed only typed halve of the command.
Thanks, I can now test it further.
Cheers,
Cedric
Hello! Do you have libs
included in your .pro
file?
contains(QMAKE_TARGET.arch, x86_64) {
LIBS += -L"C:/MySQL/mysql-5.7.22-winx64/lib" -llibmysql
} else {
LIBS += -L"C:/MySQL/mysql-5.7.22-win32/lib" -llibmysql
}
Note that you need to download the MySQL
from here MySQL Community Server and extract the data for example to C
drive. Also I suggest to copy libmysql.dll
to the application directory.
I use Qt 5.9.6
and Visual Studio 2017
compiler and it doesn’t require to build the driver for MySQL
.
Hi All,
I’m one step closer to my goal, I can now build the plugin. I cannot yet connect to my database.
Steps I’ve taken:
- Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi
- Add C:QtToolsmingw530_32bin and C:Qt5.10.1mingw53_32bin to the path
- Open cmd.exe, and enter the following commands:
c:Qt5.10.1Srcqtbasesrcpluginssqldrivers>qmake -- MYSQL_INCDIR="c:Program Files (x86)MySQLMySQL Connector C 6.1include" MYSQL_LIBDIR="c:Program Files (x86)MySQLMySQL Connector C 6.1"lib
Running configuration tests...
Checking for DB2 (IBM)... no
Checking for InterBase... no
Checking for MySQL... yes
Checking for OCI (Oracle)... no
Checking for ODBC... yes
Checking for PostgreSQL... no
Checking for SQLite (version 2)... no
Checking for TDS (Sybase)... no
Done running configuration tests.
Configure summary:
Qt Sql:
DB2 (IBM) .............................. no
InterBase .............................. no
MySql .................................. yes
OCI (Oracle) ........................... no
ODBC ................................... yes
PostgreSQL ............................. no
SQLite2 ................................ no
SQLite ................................. yes
Using system provided SQLite ......... no
TDS (Sybase) ........................... no
Qt is now configured for building. Just run 'mingw32-make'.
Once everything is built, Qt is installed.
You should NOT run 'mingw32-make install'.
Note that this build cannot be deployed to other machines or devices.
Prior to reconfiguration, make sure you remove any leftovers from
the previous build.
mingw32-make
<<lots of text>>
- Create a new Qt program, with the following options:
Qt widgets application
Name: sqlTest
Kit: Desktop Qt 5.11.1 MinGB 32 bit (default)
ClassName: (MainWindow) (default)
Version control: Git
mysql.pro
QT += core gui sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = sqlTest
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES +=
main.cpp
mainwindow.cpp
HEADERS +=
mainwindow.h
FORMS +=
mainwindow.ui
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtSql>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("world");
db.setUserName("root");
db.setPassword("PassOlyForForumQuestion");
bool ok = db.open();
qDebug()<<ok;
}
MainWindow::~MainWindow()
{
delete ui;
}
Program output:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
false
Cheers,
Cedric
Did you install the plugin ?
Did you also check that the PATH
environment variable in the Run part of the Project panel contains the folder where the MySQL .dlls can be found ?
How can I install the plugin? Where can the plugin be found? What does it look like? Where does Qt look for the plugin?
Why does the Qt runtime tell me the QMYSQL driver is available while the driver cannot be loaded? Is there any way to see why the driver did not load?
Is there a guide anywhere that works with the current version of myqsl and the current version of Qt? This guide is for mysql version 5.1: https://forum.qt.io/topic/40672/how-to-create-the-plugin-of-mysql-for-qt
Am I the first one that tries to use Qt 5 and mysql server 8?
Cheers,
Cedric
It’s explained in the documentation
In the plugins subfolder of your Qt installation under sqldrivers
.
It’s a .dll file since you’re on Windows.
Qt looks for the plugins in the subfolder named plugins unless you tweaked the qt.conf file.
Likely because it can find the plugin but will fail to load it. Most of the time it happens because the MySQL .dll files can’t be found at run time hence my suggestion in my last post.
The current Qt documentation does.
No you’re note, however MySQL server 8 saw a change in their support for their my_bool
custom type. There’s a patch to support build the Qt MySQL plugin with MySQL 8.
Thanks for your reply.
The documentation you linked (http://doc.qt.io/qt-5/sql-driver.html#building-the-drivers) assumes mysql is installed in c:mysql. This is not the case for a default installation of mysql8, as it installs itself into c:program files and c:program files (x86). This leads me to the conclusion that the install instructions on that page are outdated.
Do you know any instructions for building the plugin for qt5 and mysql 8?
Cheers,
Cedric
The doc says:
You need to get the MySQL installation files. Run SETUP.EXE and choose "Custom Install". Install the "Libs & Include Files" Module. Build the plugin as follows (here it is assumed that MySQL is installed in C:MySQL):
This simply means that it assumes that the user selected that folder to install MySQL.
Then:
cd %QTDIR%qtbasesrcpluginssqldrivers
qmake -- MYSQL_INCDIR=C:/MySQL/include "MYSQL_LIBDIR=C:/MYSQL/MySQL Server <version>/lib/opt"
nmake sub-mysql
It shows that the build is configured to use that folder.
If you put MySQL somewhere else, update the command accordingly to use that folder.
I have done the steps again:
c:Qt5.11.1Srcqtbasesrcpluginssqldrivers>qmake — MYSQL_INCDIR=»c:Program Files (x86)MySQLMySQL Connector C 6.1include» MYSQL_LIBDIR=»c:Program Files (x86)MySQLMySQL Connector C 6.1″lib
and
mingw32-make
After this, there’s no mysql.dll below C:Qt5.11.1Srcqtbasesrcpluginssqldrivers (in fact, there’s no mysql.dll on my entire C: drive)
However, this directory is newly created:
C:Qt5.11.1Srcqtbasesrcpluginssqldriverspluginssqldrivers
it contains the following files: (and a few extra files with sqlite in the name)
qsqlmysql.dll
qsqlmysqld.dll
qsqlodbc.dll
qsqlodbcd.dll
Where do I put these?
Cheers,
Cedric
@cdwijs You forgot
mingw32-make install
as shown in the documentation…
Thanks jsulm,
I’ve just done the mingw32-make install, but my Qt program does not load the driver yet.
I’ve installed Process monitor (https://docs.microsoft.com/en-us/sysinternals/downloads/procmon) to monitor the syscalls from my application. I’ve done the following steps with it:
1-run procmon.exe
2-choose filter-reset filter
3-run my program
4-choose tools-process tree
5-select my program, right click, and choose «Add process to include filter» Now only the syscalls from my program are shown.
6)ctrl-f mysql and press F3 a couple of times. Now I see BUFFER OVERFLOW. Can this be a problem?
CreateFile C:Qt5.10.1mingw53_32pluginssqldriversqsqlmysql.dll SUCCESS Desired Access: Generic Read, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: n/a, OpenResult: Opened
QueryInformationVolume C:Qt5.10.1mingw53_32pluginssqldriversqsqlmysql.dll BUFFER OVERFLOW VolumeCreationTime: 31-01-2018 09:56:48, VolumeSerialNumber: AC0C-32AB, SupportsObjects: True, VolumeLabel: WinÀ
Also, I see my program searches for libmysql.dll in the following paths:
C:ProgramDataOracleJavajavapath_target_378770LIBMYSQL.DLL
C:WindowsSysWOW64libmysql.dll
C:Windowslibmysql.dll
C:WindowsSysWOW64wbemlibmysql.dll
C:WindowsSysWOW64WindowsPowerShellv1.0libmysql.dll
C:Program FilesGitcmdlibmysql.dll
C:Program FilesTortoiseGitbinlibmysql.dll
C:QtToolsmingw530_32binlibmysql.dll
C:Program FilesPuTTYlibmysql.dll
C:Program FilesMySQLMySQL Utilities 1.6libmysql.dll
C:Qt5.10.1mingw53_32binlibmysql.dll
Mysql.dll is present on my system: C:Program Files (x86)MySQLMySQL Connector C 6.1lib, so I copy it into
C:QtToolsmingw530_32bin
Now I see libmysql.dll being successfully loaded by my program, and the error message is gone, and after supplying the correct password, I now have a connection into my mysql database.
Thank you all for your assistance.
Shall I edit my opening post with the solution, place it below, or make a new post about it?
Cheers,
Cedric
@cdwijs The solution is already at the end of this thread, just mark it as solved.
@cdwijs
I’m having trouble to execute these code lines
My cmd input:
D:Qt5.11.2Srcqtbasesrcpluginssqldrivers
qmake — MYSQL_INCDIR=»C:Program FilesMySQLMySQL Server 8.0include» MYSQL_LIBDIR=»C:Program FilesMySQLMySQL Server 8.0lib»
mingw32-make sub-mysql
My cmd output:
C:UserslucyaDesktop>D:Qt5.11.2Srcqtbasesrcpluginssqldrivers
‘D:Qt5.11.2Srcqtbasesrcpluginssqldrivers’ is not recognized as an internal or external command,
operable program or batch file.
C:UserslucyaDesktop>qmake — MYSQL_INCDIR=»C:Program FilesMySQLMySQL Server 8.0include» MYSQL_LIBDIR=»C:Program FilesMySQLMySQL Server 8.0lib»
Usage: qmake [mode] [options] [files]
QMake has two modes, one mode for generating project files based on
some heuristics, and the other for generating makefiles. Normally you
shouldn’t need to specify a mode, as makefile generation is the default
mode for qmake, but you may use this to test qmake on an existing project
Mode:
-project Put qmake into project file generation mode
In this mode qmake interprets files as files to
be built,
defaults to *; *; *; *.ts; *.xlf; *.qrc
Note: The created .pro file probably will
need to be edited. For example add the QT variable to
specify what modules are required.
-makefile Put qmake into makefile generation mode (default)
In this mode qmake interprets files as project files to
be processed, if skipped qmake will try to find a project
file in your current working directory
Warnings Options:
-Wnone Turn off all warnings; specific ones may be re-enabled by
later -W options
-Wall Turn on all warnings
-Wparser Turn on parser warnings
-Wlogic Turn on logic warnings (on by default)
-Wdeprecated Turn on deprecation warnings (on by default)
Options:
- You can place any variable assignment in options and it will be *
- processed as if it was in [files]. These assignments will be *
- processed before [files] by default. *
-o file Write output to file
-d Increase debug level
-t templ Overrides TEMPLATE as templ
-tp prefix Overrides TEMPLATE so that prefix is prefixed into the value
-help This help
-v Version information
-early All subsequent variable assignments will be
parsed right before default_pre.prf
-before All subsequent variable assignments will be
parsed right before [files] (the default)
-after All subsequent variable assignments will be
parsed after [files]
-late All subsequent variable assignments will be
parsed right after default_post.prf
-norecursive Don’t do a recursive search
-recursive Do a recursive search
-set <prop> <value> Set persistent property
-unset <prop> Unset persistent property
-query <prop> Query persistent property. Show all if <prop> is empty.
-qtconf file Use file instead of looking for qt.conf
-cache file Use file as cache [makefile mode only]
-spec spec Use spec as QMAKESPEC [makefile mode only]
-nocache Don’t use a cache file [makefile mode only]
-nodepend Don’t generate dependencies [makefile mode only]
-nomoc Don’t generate moc targets [makefile mode only]
-nopwd Don’t look for files in pwd [project mode only]
C:UserslucyaDesktop>mingw32-make sub-mysql
mingw32-make: *** No rule to make target ‘sub-mysql’. Stop.
@lucaynnofrota said in Cant connect to mysql database: QMYSQL driver not loaded:
D:Qt5.11.2Srcqtbasesrcpluginssqldrivers
This is not a command but a directory!
Please change to
cd D:Qt5.11.2Srcqtbasesrcpluginssqldrivers
then
qmake -- MYSQL_INCDIR="C:Program FilesMySQLMySQL Server 8.0include" MYSQL_LIBDIR="C:Program FilesMySQLMySQL Server 8.0lib"
@jsulm
Thanks for reply but I made a mistake. I removed CD on publication. But I have executed the correct code.
@lucaynnofrota If you get
«‘D:Qt5.11.2Srcqtbasesrcpluginssqldrivers’ is not recognized as an internal or external command,
operable program or batch file.»
it means that you’re trying to execute it. So, are you really sure you did
cd D:Qt5.11.2Srcqtbasesrcpluginssqldrivers
?
@jsulm
Yeah.
I’m using this code in .bat file!
Does anyone succeed with MySQL and Qt under Windows? I believe that nobody reaches the DB. So! no MySQL connection with Qt? Those who give their help didn’t really try, I wonder.
@realmodus
No idea what you’re talking about.
@jsulm
Your
cd D:Qt5.11.2Srcqtbasesrcpluginssqldrivers
I suspect this didn’t work for OP as it needs to be cd /d D:...
to make the D:
drive the current drive for the subsequent qmake
command to be on the right drive, else it’ll still be on C:
?
@JonB You’re right I didn’t think about the drive
we had the same driver nod loaded issue. we fixed by switch compiler as 32bit from originally 64bit to compile application in Qt. Hope this help. some of our machine is 32bit machine.
@cdwijs I wish to information you that I have been following the steps you took to build QMySQL driver for Qt 5.13.0 though. However, I got lost at the point you gave three (3) steps you took to get qmake identify mysql driver because at that point my qmake could not identify the driver:
-
Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi
-
Add C:QtToolsmingw530_32bin and C:Qt5.10.1mingw53_32bin to the path
-
Open cmd.exe, and enter the following commands:
-
Are there some other things you did which, perhaps, you did not mention on the steps?
-
In step 2 of your procedure, you said you added C:QtToolsmingw530_32bin and C:Qt5.10.1mingw53_32bin to the path. Did you mean path of system variable?
I installed MySQL 8.016 community edition and used the same c++ connector, 6.1 32-bit you used.
Followings are the commands I used but qmake could detect MySQL source driver:
cd C:QtQt5.13.05.13.0Srcqtbasesrcpluginssqldrivers
qmake — MYSQL_INCDIR=C:Program~Files~(x86)MySQLMySQL~Connector~C~6.1include «MYSQL_LIBDIR=C:Program~Files~(x86)MySQLMySQL~Connector~C~6.1libopt»
Can you help where I got it wrong?
Cheers,
Heman.
@heman said in Cant connect to mysql database: QMYSQL driver not loaded:
Are there some other things you did which, perhaps, you did not mention on the steps?
«mingww32-make install» after successful build is missing.
You should not set your PATH globally, do it in the cmd.exe window where you build.
These paths looks strange:
«C:Program~Files~(x86)MySQLMySQL~Connector~C~6.1include «MYSQL_LIBDIR=C:Program~Files~(x86)MySQLMySQL~Connector~C~6.1libopt»»
Use complete paths with escaped spaces. Even better would be to install MySQL stuff in a directory without spaces.
I get it now. It works.
I might have included some kind of atrocities who knows? However, these are the steps I took:
- I installed MySQL community edition
- I installed mysql connector c 6.1
- I created a .bat file with the following commands: C:WindowsSystem32cmd.exe /E:ON /V:ON /K C:QtQt5.13.05.13.0mingw73_32binqmake.exe
SET _ROOT=C:QtQt5.13.0
SET PATH=C:QtQt5.13.05.13.0mingw73_32bin;C:QtQt5.13.0Toolsmingw730_32bin;%PATH% - I run cd C:QtQt5.13.05.13.0Srcqtbasesrcpluginssqldrivers
- I run qmake — MYSQL_INCDIR=»C:Program Files (x86)MySQLMySQL Connector C 6.1include» MYSQL_LIBDIR=»C:Program Files (x86)MySQLMySQL Connector C 6.1lib»
mingw32-make
ming32-make install - And lastly, I copied libmysql.dll from C:Program Files (x86)MySQLMySQL Connector C 6.1lib to C:QtQt5.13.0Toolsmingw730_32bin
@cdwijs said in Cant connect to mysql database: QMYSQL driver not loaded:
Hi All,
I’m one step closer to my goal, I can now build the plugin. I cannot yet connect to my database.
Steps I’ve taken:
- Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi
- Add C:QtToolsmingw530_32bin and C:Qt5.10.1mingw53_32bin to the path
Hi,
I am struggling with the same issue, where exactly did you add C:QtToolsmingw530_32bin and C:Qt5.10.1mingw53_32bin to?
@hobbyProgrammer I’ve added them to the PATH. On widows7, you can find that setting here:
start->control panel->system and security->system->Advanced system settings->Advanced->Environment Variables->System variables->Path->Edit…
You can see the current value of the path variable by start->run->cmd and the command:
echo %PATH%
@cdwijs thanks, but unfortunately it didn’t work for me
@hobbyProgrammer Did you log out and log in after changing PATH?
Bar-bar1an 1 / 1 / 6 Регистрация: 12.12.2014 Сообщений: 50 |
||||||||
1 |
||||||||
10.08.2016, 21:16. Показов 3207. Ответов 10 Метки нет (Все метки)
В переменной PATH прописал путь к папке bin (mysql). Также скопировал libmysql.dll в папку C:QtQt5.7.05.7mingw53_32bin но все равно получаю ->
Добавлено через 2 часа 34 минуты
__________________
0 |
93 / 93 / 33 Регистрация: 17.03.2012 Сообщений: 536 |
|
10.08.2016, 21:31 |
2 |
Возьмите libmysql.dll и положите рядом с исполняемым файлом собранного проекта в папку sqldrivers рядом с экзешником. Либо в папку plugins, там же. Не помню точно, как папка должна называться.
0 |
1 / 1 / 6 Регистрация: 12.12.2014 Сообщений: 50 |
|
10.08.2016, 22:05 [ТС] |
3 |
положил в -> C:QtQt5.7.05.7mingw53_32pluginssqldrivers. без изменений
0 |
KreshDiz 3 / 3 / 1 Регистрация: 29.11.2010 Сообщений: 115 |
||||||||
09.09.2018, 18:53 |
5 |
|||||||
Здравствуйте. QSqlDatabase: QMYSQL driver not loaded В интернете множество решений, но все они уже устарели, т.к. давно обновились версии ПО, пропали папки и программы на которые ссылаются инструкции. Прошу помощи в решении проблемы. Как собрать библиотеку? p.s.QT 5.11.1 на сайте доступна только x86, Кликните здесь для просмотра всего текста
Добавлено через 34 минуты Setting up environment for Qt usage… C:QtQt5.11.15.11.1mingw53_32>set mysql = C:PROGRA~1MySQLMYSQLS~1.0 C:QtQt5.11.15.11.1mingw53_32>cd C:QtQt5.11.15.11.1Srcqtbasesrcpluginssqldr iversmysql C:QtQt5.11.15.11.1Srcqtbasesrcpluginssqldr iversmysql>qmake «INCLUDEPATH+=%mysql%\include» «LIBS+=%mysql%\lib\libmysql.lib» -o Makefile mysql.pro C:QtQt5.11.15.11.1Srcqtbasesrcpluginssqldr iversmysql>
0 |
0 / 0 / 0 Регистрация: 29.10.2016 Сообщений: 30 |
|
17.01.2019, 21:22 |
6 |
KreshDiz, Ты решил проблему?
0 |
134 / 26 / 8 Регистрация: 09.02.2017 Сообщений: 175 |
|
18.01.2019, 01:15 |
7 |
misha008, зачем вы уже не в первый раз поднимаете старые темы?
0 |
0 / 0 / 0 Регистрация: 29.10.2016 Сообщений: 30 |
|
18.01.2019, 11:43 |
8 |
Нет не решил( Я не знаю откуда взять эти библеотеки dll Добавлено через 41 секунду
0 |
FRIEND_ 134 / 26 / 8 Регистрация: 09.02.2017 Сообщений: 175 |
||||
18.01.2019, 12:36 |
9 |
|||
misha008, конкретно в этом коде, который здесь представлен, как минимум, нужно указать расширение файла в этой строке:
0 |
0 / 0 / 0 Регистрация: 29.10.2016 Сообщений: 30 |
|
18.01.2019, 13:08 |
10 |
У меня для Х32 версии получалось запустить и без этого. У меня на ПК отсутствуют нужные драва(dll не находит): Я нашел, что это из-за windows8.1 и нужно поставить её заново.
0 |
weterok 36 / 28 / 9 Регистрация: 11.11.2018 Сообщений: 163 |
||||
19.01.2019, 18:20 |
11 |
|||
Вообще чтобы Qt приложение под Win видело необходимые dll в папке с программой, нужно в main написать следующее:
1 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
19.01.2019, 18:20 |
11 |
В процессе использования Qt для работы с базой данных MySQL после использования Qt для написания кода для подключения к базе данных MySQL во время компиляции и отладки выдается сообщение об ошибке QSqlDatabase: драйвер QMYSQL не загружен, что означает, что приложению Qt не удается подключиться к базе данных MySQL. Ошибка показана на рисунке ниже:
("QSQLITE", "QODBC", "QODBC3", "QPSQL", "QPSQL7")
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
"Driver not loaded Driver not loaded"
Среда разработки этого проекта (решения):
(1) Операционная система: Windows10
(2) Версия MySQL: 8.0MySql скачать
(3) Версия Qt: 5.14.1Qt5.14.1 скачать
(4) Версия QtCreator: 4.11.0
Проанализировать причину «QSqlDatabase: драйвер QMYSQL не загружен»
Согласно сообщению об ошибке на изображении выше, проверьте официальный документ, ссылка:https://doc.qt.io/qt-5/sql-driver.html#qmysql-for-mysql-4-and-higher,Получите соответствующую информацию следующим образом
(1) Модуль Qt SQL использует подключаемый модуль драйвера для связи с различными API баз данных.
(2) Поддерживаются следующие базы данных:
Driver name | DBMS |
---|---|
QDB2 | IBM DB2 (version 7.1 and above) |
QIBASE | Borland InterBase |
QMYSQL | MySQL (version 5.0 and above) |
QOCI | Oracle Call Interface Driver |
QODBC | Open Database Connectivity (ODBC) — Microsoft SQL Server and other ODBC-compliant databases |
QPSQL | PostgreSQL (versions 7.3 and above) |
QSQLITE2 | SQLite version 2Note: obsolete since Qt 5.14 |
QSQLITE | SQLite version 3 |
QTDS | Sybase Adaptive ServerNote: obsolete since Qt 4.7 |
Согласно сообщению об ошибке, доступны следующие драйверы: QSQLITE QODBC QODBC3 QPSQL QPSQL7, а драйвер QMYSQL отсутствует. Итак, причины проблемы с позиционированием:Отсутствие драйвера QMYSQL.
Скомпилировать драйвер MySQL
(1) Скомпилируйте драйвер
Проверьте путь установки Qt на компьютере: E: ProgramData Qt Qt5.14.1 5.14.1 mingw73_64 plugins sqldrivers подключаемый модуль sqldrivers, как показано ниже
[Не удалось передать изображение по внешней ссылке. На исходном сайте может быть механизм защиты от хотлинкинга. Рекомендуется сохранить изображение и загрузить его напрямую (img-j5HUM609-1583739250397) (C: Users AdminCode AppData Roaming Typora typora-user-images image-20200309150658854.png)]
Обнаружено, что нет подключаемого модуля драйвера, связанного с MySQL.
Исходная версия Qt5.13 не включает плагин драйвера для управления MySQL, поэтому вам нужно скомпилировать плагин самостоятельно. Процесс компиляции плагина выглядит следующим образом:
1. Используйте QtCreator, чтобы открыть проект mysql.proE:ProgramDataQtQt5.14.15.14.1Srcqtbasesrcpluginssqldriversmysql
Откройте файл проекта (исходное содержимое) следующим образом.
Модификация элемента управления выглядит следующим образом
Дайте код, скопируйте и замените самостоятельно
TARGET = qsqlmysql
HEADERS += $$PWD/qsql_mysql_p.h
SOURCES += $$PWD/qsql_mysql.cpp $$PWD/main.cpp
#QMAKE_USE += mysql
OTHER_FILES += mysql.json
PLUGIN_CLASS_NAME = QMYSQLDriverPlugin
include(../qsqldriverbase.pri)
# Путь - это путь к файлу заголовка Mysql (включая)
INCLUDEPATH +="E:Program FilesMySQLmysql-8.0.18-winx64include"
# Это путь к файлу библиотеки MySQl
LIBS +="E:Program FilesMySQLmysql-8.0.18-winx64liblibmysql.lib"
# Для облегчения поиска вы можете добавить оператор, который используется для указания местоположения скомпилированного результата
DESTDIR = ../mysql/lib/
Скомпилируйте программу после ее добавления (примечание: здесь используется бит MinGw64)
После успешной компиляцииE:ProgramDataQtQt5.14.15.14.1Srcqtbasesrcpluginssqldriversmysql
Под каталогом будет дополнительный каталог lib
2. Скопируйте эти три файла вE:ProgramDataQtQt5.14.15.14.1mingw73_64pluginssqldrivers
в
(2) Добавить пакет расширения MySql
Добавить пакет расширения для подключения к MySQLlibmysql.dll
с участиемlibmysql.lib
, Этот пакет находится в нашем каталоге установки MySqlE:Program FilesMySQLmysql-8.0.18-winx64lib
в;
Добавьте пакет расширения в каталог установки QtE:ProgramDataQtQt5.14.15.14.1mingw73_64bin
в:
Пока что Qt может подключаться к базе данных MySQL.
|
Автор | Тема: Ошибка QMYSQL driver not loaded (Прочитано 40272 раз) |
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
In the process of using Qt to operate the MySQL database, after using Qt to write the code to connect to the MySQL database, the error QSqlDatabase: QMYSQL driver not loaded is reported during compilation and debugging, which means that the Qt application fails to connect to the MySQL database. The error is shown in the figure below:
("QSQLITE", "QODBC", "QODBC3", "QPSQL", "QPSQL7")
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
"Driver not loaded Driver not loaded"
The development environment of this project (solution) is:
(1) Operating system: Windows10
(2) The MySQL version is: 8.0MySql download
(3) The Qt version is: 5.14.1Qt5.14.1 download
(4) QtCreator version is: 4.11.0
Analyze the reason for «QSqlDatabase: QMYSQL driver not loaded»
According to the error message in the above picture, consult the official document, link:https://doc.qt.io/qt-5/sql-driver.html#qmysql-for-mysql-4-and-higher,Get relevant information as follows
(1) The Qt SQL module uses a driver plug-in to communicate with different database APIs.
(2) The supported databases are as follows:
Driver name | DBMS |
---|---|
QDB2 | IBM DB2 (version 7.1 and above) |
QIBASE | Borland InterBase |
QMYSQL | MySQL (version 5.0 and above) |
QOCI | Oracle Call Interface Driver |
QODBC | Open Database Connectivity (ODBC) — Microsoft SQL Server and other ODBC-compliant databases |
QPSQL | PostgreSQL (versions 7.3 and above) |
QSQLITE2 | SQLite version 2Note: obsolete since Qt 5.14 |
QSQLITE | SQLite version 3 |
QTDS | Sybase Adaptive ServerNote: obsolete since Qt 4.7 |
According to the error message, the available drivers are: QSQLITE QODBC QODBC3 QPSQL QPSQL7, and there is no QMYSQL driver. The reasons for the positioning problem are:Lack of QMYSQL driver.
Compile MySQL driver
(1) Compile the driver
Check the computer Qt installation path: E:ProgramDataQtQt5.14.15.14.1mingw73_64pluginssqldrivers sqldrivers plug-in, as follows
[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-j5HUM609-1583739250397)(C:UsersAdminCodeAppDataRoamingTyporatypora-user-images image-20200309150658854.png)]
Found that there is no driver plug-in related to MySQL.
The original Qt5.13 version does not include a driver plugin to drive MySQL, so you need to compile the plugin yourself. The process of compiling the plug-in is as follows:
1. Use QtCreator to open the mysql.pro projectE:ProgramDataQtQt5.14.15.14.1Srcqtbasesrcpluginssqldriversmysql
Open the project file (initial content) as follows
The modification of the control is as follows
Give the code, copy and replace by yourself
TARGET = qsqlmysql
HEADERS += $$PWD/qsql_mysql_p.h
SOURCES += $$PWD/qsql_mysql.cpp $$PWD/main.cpp
#QMAKE_USE += mysql
OTHER_FILES += mysql.json
PLUGIN_CLASS_NAME = QMYSQLDriverPlugin
include(../qsqldriverbase.pri)
#The path is the Mysql header file (include) path
INCLUDEPATH +="E:Program FilesMySQLmysql-8.0.18-winx64include"
#This is the library file path of MySQl
LIBS +="E:Program FilesMySQLmysql-8.0.18-winx64liblibmysql.lib"
#In order to facilitate the search, you may wish to add a statement, which is used to indicate the location of the compiled result output
DESTDIR = ../mysql/lib/
Compile the program after adding it (note: MinGw64 bit is used here)
After successful compilationE:ProgramDataQtQt5.14.15.14.1Srcqtbasesrcpluginssqldriversmysql
There will be an extra lib directory under the directory
2. Copy these three files toE:ProgramDataQtQt5.14.15.14.1mingw73_64pluginssqldrivers
in
(2) Add MySql extension package
Add extension package for MySQL connectionlibmysql.dll
withlibmysql.lib
, This package is in our MySql installation directoryE:Program FilesMySQLmysql-8.0.18-winx64lib
in;
Add the extension package to the Qt installation directoryE:ProgramDataQtQt5.14.15.14.1mingw73_64bin
in:
So far, Qt can connect to the MySQL database.
При таком коде:
db = QtSql.QSqlDatabase.addDatabase(‘QMYSQL’)
db.setHostName(‘localhost’)
db.setUserName(‘root’)
db.setPassword(‘1234’)
db.setDatabaseName(‘test’)
db.open()
print(db.lastError().text())
В консоль выводится следующие:
python gui.py
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
Driver not loaded Driver not loaded
Библиотеки qsqlite.dll, qsqlmysql.dll, qsqlodbc.dll, qsqlpsql.dll существуют и находятся в папке
C:PythonLibsite-packagesPyQt5Qtpluginssqldrivers
Использую Windows 10 x64, Python 3.6.1, PyQt 5.8, MySql 5.7.
Такой вопрос уже был задан здесь, но решение, которое в нем содержится, мою проблему не решило.
Что надо сделать, чтобы установить соединение с базой?
Ответ
Для подключения нужно добавлять в среду переменных в переменную PATH полный путь к /MySQL/lib.
В моем случае полный путь выглядит так:
C:Program Files (x86)MySQLMySQL Server 5.7lib
Затем перезагрузить или выйти из системы, чтобы это добавление вступило в силу, вот что я и сделал, и в чем состояло решение проблемы.
- Forum
- Qt
- Newbie
- QSqlDatabase: QMYSQL driver not loaded but available
-
QSqlDatabase: QMYSQL driver not loaded but available
Yeah hello there, I’m really new here.
So here’s the problem.QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
To copy to clipboard, switch view to plain text mode
I’ve checked many forums already and have done things so far:
1) This is my .pro fileQT += core
QT += sql
QT -= gui
TARGET = DB
CONFIG += console
CONFIG -= app_bundle
QTPLUGIN += QSQLMYSQL
TEMPLATE = app
SOURCES += main.cpp
To copy to clipboard, switch view to plain text mode
2) This is my sqldrivers folder:
alex@alex-Laptop:~/Programming/Qt/5.1.0/gcc_64/plugins/sqldrivers$ ls
libqsqlite.so libqsqlmysql.so libqsqlpsql.so
To copy to clipboard, switch view to plain text mode
3) Have also copied sqldrivers folder to project folder.
Non of these helped an error still exists.
I have read almost everything about my problem but nothing helped.
Please help newbie with the fix.Thanks in advance
-
Re: QSqlDatabase: QMYSQL driver not loaded but available
post the part of the code where you open the database connection
-
Re: QSqlDatabase: QMYSQL driver not loaded but available
db.setHostName("teachinglessons.abcz8.com");
db.setPort(3306);
db.setDatabaseName("teachi4_test");
db.setUserName("alex");
db.setPassword("123");
qDebug()<<db.open();
To copy to clipboard, switch view to plain text mode
-
Re: QSqlDatabase: QMYSQL driver not loaded but available
Try giving the database a name:
db = QSqlDatabase::addDatabase("QMYSQL", "my_sql_db");
To copy to clipboard, switch view to plain text mode
Plus, have you built the plugins?
http://harmattan-dev.nokia.com/docs/…x-and-mac-os-x
-
Re: QSqlDatabase: QMYSQL driver not loaded but available
Nothing change unfortunately
-
Re: QSqlDatabase: QMYSQL driver not loaded but available
Read my editing, i think you are missing the step of building the plugins
-
Re: QSqlDatabase: QMYSQL driver not loaded but available
Originally Posted by KillGabio
Read my editing, i think you are missing the step of building the plugins
There’s no /src/plugins/sqldrivers/mysql in my qt folder should i create it?
Sorry for stupid question
-
Re: QSqlDatabase: QMYSQL driver not loaded but available
I have this path for example:
C:QtSDKQtSources4.8.1srcpluginssqldriversmy sqls
containing main.cpp, mysql.pro and readme.
Im running on windows, but you should have the same path i assume. Somewhere you need to have the files to generate and build your drivers.
-
Re: QSqlDatabase: QMYSQL driver not loaded but available
You have the Qt plugin for MySQL and it is recognised far enough to tell your program it exists. Are the MySQL run-time libraries (on which an actual database connection would depend) available on your machine?
-
12th July 2013, 10:06
#10
Re: QSqlDatabase: QMYSQL driver not loaded but available
KillGabio
There’s nothing like that found in my QtChrisW67
Yes but same problem
-
12th July 2013, 10:28
#11
Re: QSqlDatabase: QMYSQL driver not loaded but available
On Windows when I had the same problem i had to include the .dll of the database in this path:
C:QtSDKDesktopQt4.8.1mingwpluginssqldrivers
So that the compiler knows the libraries. For example there I have: qsqlite4.dll, qsqlocid4.dll, etc. I think you are missing the same files but for Unix (.so shared objects)
-
12th July 2013, 10:31
#12
Re: QSqlDatabase: QMYSQL driver not loaded but available
alex@alex-Laptop:~/Programming/Qt/5.1.0/gcc_64/plugins/sqldrivers$ ls
libqsqlite.so libqsqlmysql.so libqsqlpsql.so
I have the libraries there
-
12th July 2013, 12:11
#13
Re: QSqlDatabase: QMYSQL driver not loaded but available
Those are the Qt plugins, not the MySQL runtime libraries. You are looking for libmysqlclient.so somewhere on your system.
-
12th July 2013, 17:53
#14
Re: QSqlDatabase: QMYSQL driver not loaded but available
Originally Posted by ChrisW67
Those are the Qt plugins, not the MySQL runtime libraries. You are looking for libmysqlclient.so somewhere on your system.
Yeah I found them. What should I do with them?
locaalex@alex-Laptop:~$ locate libmysqlclient.so
/usr/lib/i386-linux-gnu/libmysqlclient.so.18
/usr/lib/i386-linux-gnu/libmysqlclient.so.18.0.0
/usr/lib/x86_64-linux-gnu/libmysqlclient.so
/usr/lib/x86_64-linux-gnu/libmysqlclient.so.18
/usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0
To copy to clipboard, switch view to plain text mode
-
12th July 2013, 20:25
#15
Re: QSqlDatabase: QMYSQL driver not loaded but available
Include them in your .pro. Example:
INCLUDEPATH += "C:/oraclexe/app/oracle/product/11.2.0/server/oci/lib/MSVC/vc10"
LIBS += -L"C:/Qt/Los taninos-killgabio/qextserialport/build" -lqextserialportd
To copy to clipboard, switch view to plain text mode
-
12th July 2013, 21:42
#16
Re: QSqlDatabase: QMYSQL driver not loaded but available
Originally Posted by alexandrius
Yeah I found them. What should I do with them?
Nothing , they should be in a default library search location for the system.
What is the result when you run:
$ ldd ~/Programming/Qt/5.1.0/gcc_64/plugins/sqldrivers/libqsqlmysql.so
To copy to clipboard, switch view to plain text mode
Are there any libraries reported missing? You might try this:
$ objdump -x /home/chrisw/Qt5.1.0/5.1.0/gcc_64/plugins/sqldrivers/libqsqlmysql.so | grep NEEDED
To copy to clipboard, switch view to plain text mode
Does it show the same version number on the mysql related line as in your libs64 folder?
Last edited by ChrisW67; 12th July 2013 at 21:50.
-
The following user says thank you to ChrisW67 for this useful post:
adutzu89 (17th December 2013)
-
30th July 2013, 18:17
#17
Re: QSqlDatabase: QMYSQL driver not loaded but available
I’m reviving this thread as it seems to be inactive without a answer to the problem and I was dealing with exactly the same problem for the past few days.
(with Opensuse 12.3, x86_64).it seems that the compiled plugin that comes with the qt (qt-linux-opensource-5.1.0-x86_64-offline.bin) requires /usr/lib64/libmysqlclient_r.so.16 and opensuse comes with .18. So
doing
/usr/lib64 # ln -s libmysqlclient_r.so libmysqlclient_r.so.16seems to solve the problem.
regards,
-
The following user says thank you to artome for this useful post:
adutzu89 (17th December 2013)
-
3rd March 2014, 17:57
#18
Re: QSqlDatabase: QMYSQL driver not loaded but available
/usr/lib/i386-linux-gnu$ ln -s libmysqlclient_r.so libmysqlclient_r.so.16
Fixed my problem
Thanks,
Selva
-
The following user says thank you to tselvakumars for this useful post:
martonmiklos (6th July 2014)
-
Re: QSqlDatabase: QMYSQL driver not loaded but available
I have had the similar problem on Kubuntu 14.04 64 bit with the latest 5.3.1 Qt relase downloaded from the qt-project and installed to the /opt.
The Ubuntu 14.04 ships with libmysqlclient 18 while the Qt 5.3.1 is built with 16. So the creating of a symlink like above did not solved my issue.
Finally I have downloaded the libmysqlclient 16 from here:
http://packages.ubuntu.com/lucid/amd…ent16/downloadAnd extraceted the library files to my /usr/lib/x86_64-linux-gnu folder.
-
29th March 2016, 09:38
#20
Re: QSqlDatabase: QMYSQL driver not loaded but available
Had the same problem => Plugin QMYSQL & QMYSQL 3 were available but couldn’t load them :
«QSqlDatabase: QMYSQL driver not loaded / QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7»Works for me on Windows with Qt SDK 5.6.0 (32bit version with mingw 4.9.2 32bit included) :
— Downloaded MySQL 32bit in zip archive (mine was v5.7.11)
— Extracted it to C:/MySQL
— Copied «C:QtQMySQLliblibmysql.dll» and «C:QtQMySQLliblibmysqld.dll» to Windows/System32 (to avoid the «cannot found -llibmysql» compilation error)
— Compile with «How to Build the QMYSQL Plugin on Windows» on http://doc.qt.io/qt-5/sql-driver.html#qmysql (my command was «qmake «INCLUDEPATH+=C:QtQMySQLinclude» «LIBS+=C:QtQMySQLliblibmysql.lib» sql.pro» and «mingw32-make»)
— After compilation succeeded, copy (the freshly compiled) Qt5Sql.dll & Qt5Sqld.dll from «C:QtQt5.6.05.6Srcqtbaselib» to your application build directory
— Restart QtCreator, that should work
Similar Threads
-
Replies: 12
Last Post: 29th March 2017, 15:43
-
Replies: 7
Last Post: 15th November 2014, 08:29
-
Replies: 1
Last Post: 9th January 2011, 19:39
-
Replies: 3
Last Post: 1st June 2010, 14:09
-
Replies: 6
Last Post: 28th April 2009, 07:58
Bookmarks
Bookmarks

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
- BB code is On
- Smilies are On
- [IMG] code is On
- [VIDEO] code is On
- HTML code is Off
Forum Rules
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.
While using Qt, I faced the problem where I could not get the QMysql working. It will keep giving me the following error:
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
I checked out some threads that might give me a lead on solving this issue. I tried all the methods mentioned in this thread but none worked.
I found another lead, which was building the driver file from source and this is introduced in the official Qt resources. I will not write about how to download the source code of a given Qt version.
BTW, my environment is Ubuntu 14.04 (64bit) and have installed Qt5.7 and Qt5.8 through offline installer. Thus, I have /opt/Qt5.7 and /opt/Qt5.8.
Here I will log my attempt to follow the tutorial:
the guide says that the below are the commands that I must used to build the .so file that will allow me to work with mysql.
$ cd ~ $ cd Downloads/qt-everywhere-opensource-src-5.8.0/qtbase/src/plugins/sqldrivers/mysql $ qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro $ make
However, I ran into a few errors here
error1) Qt 5.7 5.8 version mismatch
I went into the 5.8.0 version source and executed the qmake command. But it gave me an error like this:
$ qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro Project ERROR: Could not find feature framework. Project ERROR: Could not find feature c++11.
I found that this error is probably due to the Qt version mismatch. As you can see below, the qmake tool is using Qt 5.7.0. One could make modifications so that the qmake tool will use Qt 5.8.0 but I simple decided to download the Qt 5.7.0 source package and run the sequence above.
$ qmake --version QMake version 3.0 Using Qt version 5.7.0 in /opt/Qt5.7.0/5.7/gcc_64/lib
error2)
okay, now that I have changed to the Qt 5.7.0 source package, I hoped that the qmake ....
command would work this time. However I ran into an error like below:
$ qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro $ make make: Nothing to be done for `first'.
As you can see I have ran into an error in the make
command. The reason behind this error was that I had already done this before writing this post and haven’t cleaned it. If you are doing this for the first time, then you probably won’t run into this problem.
This can be cleaned with
$ make clean rm -f .moc/moc_qsql_mysql_p.cpp rm -f .moc/main.moc rm -f .obj/main.o .obj/qsql_mysql.o .obj/moc_qsql_mysql_p.o rm -f *~ core *.core
now that we’ve clean the build, redoing the ‘make’ command should show proper building logs. And in the end, it will show a message something like below:
$ make /opt/Qt5.7.0/5.7/gcc_64/bin/moc -DQT_NO_MTDEV -DQT_NO_LIBUDEV -DQT_NO_TSLIB -DQT_NO_LIBINPUT -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_PLUGIN -DQT_... ... g++ -Wl,--no-undefined -Wl,-O1 -Wl,--enable-new-dtags -Wl,-z,origin -Wl,-rpath,$ORIGIN/../../lib -Wl,-rpath,$ORIGIN/../../lib -shared -o libqsqlmysql.so .obj/main.o .obj/qsql_mysql.o .obj/moc_qsql_mysql_p.o -L/usr/local/lib -L/usr/lib64/mysql -lmysqlclient_r -lz -lcrypt -lnsl -lm -lssl -lcrypto -L/opt/Qt5.7.0/5.7/gcc_64/lib -lQt5Sql -lQt5Core -lpthread mv -f libqsqlmysql.so ../../../../plugins/sqldrivers/
In the last line you can see that the built .so file has been moved to some other directory. Go to the directory and you will see the freshly built .so file. ( you don’t need to do this since you have once more step left in the original build directory)
$ cd ../../../../plugins/sqldrivers/ $ lslibsqlmysql.so
back to the build directory( sourcepackagedir/qtbase/src/plugins/sqldrivers/mysql) , the final is the make install
command as introduced in the Qt official guide. However, you need to do this with sudo.
$ sudo make install install -m 755 -p ../../../../plugins/sqldrivers/libqsqlmysql.so /opt/Qt5.7.0/5.7/gcc_64/plugins/sqldrivers/libqsqlmysql.so strip --strip-unneeded /opt/Qt5.7.0/5.7/gcc_64/plugins/sqldrivers/libqsqlmysql.so install -m 644 -p /home/chadrick/Downloads/qt-everywhere-opensource-src-5.7.0/qtbase/lib/cmake/Qt5Sql/Qt5Sql_QMYSQLDriverPlugin.cmake /opt/Qt5.7.0/5.7/gcc_64/lib/cmake/Qt5Sql/
as you can see, the built .so file will be moved to its appropriate location.
I think after this, you will not run into the QMYSQL driver not loaded
error.
Raspberry Pi
Installed Ubuntu mate. The QMYSQL not found error can be solved by installing a package:
$ sudo apt install libqt5sql5-mysql