QSqlDatabase: MYSQL driver not loaded
-
Hey everyone,
I followed the documentation to put in place a database.
But i got the following warning when i click :
QSqlDatabase: MYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QPSQL
See my code :
#include "pageinscription.h" #include "ui_pageinscription.h" #include <QSqlQuery> pageinscription::pageinscription(QWidget *parent) : QDialog(parent), ui(new Ui::pageinscription) { ui->setupUi(this); } pageinscription::~pageinscription() { delete ui; } void pageinscription::inscrire() { database = QSqlDatabase::addDatabase("MYSQL"); database.setHostName("localhost"); database.setDatabaseName("bossom"); database.setUserName("root"); database.setPassword(""); if (database.open()) { QString identifiant = ui->identifiant->text(); QString motdepasse = ui->motdepasse->text(); QSqlQuery qry; qry.prepare("INSERT INTO utilisateur (identifiant, motdepasse)" "VALUES (:utilisateur,:motdepasse)"); qry.bindValue(":identifiant", identifiant); qry.bindValue(":motdepasse", motdepasse); if(qry.exec()) { QMessageBox::information(this,"Inséré","Vous êtes bien inscrits"); } else{ QMessageBox::information(this,"Pas inséré","Les données ne se sont pas bien insérées"); } } else { QMessageBox::information(this,"Not connected","Database is not connected"); } } void pageinscription::on_pushButton_2_clicked() { database = QSqlDatabase::addDatabase("MYSQL"); database.setHostName("localhost"); database.setDatabaseName("bossom"); database.setUserName("bossom"); database.setPassword("bossom"); bool ok = database.open(); if (database.open()) { QString identifiant = ui->identifiant->text(); QString motdepasse = ui->motdepasse->text(); QSqlQuery qry; qry.prepare("INSERT INTO utilisateur (identifiant, motdepasse)" "VALUES (:utilisateur,:motdepasse)"); qry.bindValue(":identifiant", identifiant); qry.bindValue(":motdepasse", motdepasse); if(qry.exec()) { QMessageBox::information(this,"Inséré","Vous êtes bien inscrits"); } else{ QMessageBox::information(this,"Pas inséré","Les données ne se sont pas bien insérées"); } } else { QMessageBox::information(this,"Not connected","Database is not connected"); } }
Thank you :)
-
Hey everyone,
I followed the documentation to put in place a database.
But i got the following warning when i click :
QSqlDatabase: MYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QPSQL
See my code :
#include "pageinscription.h" #include "ui_pageinscription.h" #include <QSqlQuery> pageinscription::pageinscription(QWidget *parent) : QDialog(parent), ui(new Ui::pageinscription) { ui->setupUi(this); } pageinscription::~pageinscription() { delete ui; } void pageinscription::inscrire() { database = QSqlDatabase::addDatabase("MYSQL"); database.setHostName("localhost"); database.setDatabaseName("bossom"); database.setUserName("root"); database.setPassword(""); if (database.open()) { QString identifiant = ui->identifiant->text(); QString motdepasse = ui->motdepasse->text(); QSqlQuery qry; qry.prepare("INSERT INTO utilisateur (identifiant, motdepasse)" "VALUES (:utilisateur,:motdepasse)"); qry.bindValue(":identifiant", identifiant); qry.bindValue(":motdepasse", motdepasse); if(qry.exec()) { QMessageBox::information(this,"Inséré","Vous êtes bien inscrits"); } else{ QMessageBox::information(this,"Pas inséré","Les données ne se sont pas bien insérées"); } } else { QMessageBox::information(this,"Not connected","Database is not connected"); } } void pageinscription::on_pushButton_2_clicked() { database = QSqlDatabase::addDatabase("MYSQL"); database.setHostName("localhost"); database.setDatabaseName("bossom"); database.setUserName("bossom"); database.setPassword("bossom"); bool ok = database.open(); if (database.open()) { QString identifiant = ui->identifiant->text(); QString motdepasse = ui->motdepasse->text(); QSqlQuery qry; qry.prepare("INSERT INTO utilisateur (identifiant, motdepasse)" "VALUES (:utilisateur,:motdepasse)"); qry.bindValue(":identifiant", identifiant); qry.bindValue(":motdepasse", motdepasse); if(qry.exec()) { QMessageBox::information(this,"Inséré","Vous êtes bien inscrits"); } else{ QMessageBox::information(this,"Pas inséré","Les données ne se sont pas bien insérées"); } } else { QMessageBox::information(this,"Not connected","Database is not connected"); } }
Thank you :)
@Cervo2paille
Since you want to access a MySQL database what did you do about installing the MySQL driver? -
Hi,
Beside the question of @JonB, you also have a typo. It's the
QMYSQL
driver that you are trying to load.@SGaist Thanks for your answer.
In fact there was an error in my "QMYSQL".I followed the doc : https://doc.qt.io/qt-6/sql-driver.html#qmysql
But i got the same error : it didn't work, i got the same message.
Someone has a good tutorial to connect to my MySQL (Xampp) ?
I copied the lib and dll in my compilator, in my project... so way.Thanks
-
@SGaist Thanks for your answer.
In fact there was an error in my "QMYSQL".I followed the doc : https://doc.qt.io/qt-6/sql-driver.html#qmysql
But i got the same error : it didn't work, i got the same message.
Someone has a good tutorial to connect to my MySQL (Xampp) ?
I copied the lib and dll in my compilator, in my project... so way.Thanks
@Cervo2paille said in QSqlDatabase: MYSQL driver not loaded:
I followed the doc : https://doc.qt.io/qt-6/sql-driver.html#qmysql
So, did you build and install the driver for MySQL? See the "How to Build the QMYSQL Plugin on Windows" chapter in the link you posted.
-
@Cervo2paille said in QSqlDatabase: MYSQL driver not loaded:
I followed the doc : https://doc.qt.io/qt-6/sql-driver.html#qmysql
So, did you build and install the driver for MySQL? See the "How to Build the QMYSQL Plugin on Windows" chapter in the link you posted.
@jsulm Hey,
Sure i did. And after that I saw the note that notice it don't work and we must install "full MySQL Server (x64 only) or the MariaDB C Connector". I tried... and got the same error, again. :)
Thanks -
@jsulm Hey,
Sure i did. And after that I saw the note that notice it don't work and we must install "full MySQL Server (x64 only) or the MariaDB C Connector". I tried... and got the same error, again. :)
Thanks@Cervo2paille said in QSqlDatabase: MYSQL driver not loaded:
I tried... and got the same error, again. :)
What exactly did you try?
You need to install MariaDB C Connector before you build the plug-in. And then you pass the paths to the CMake call like shown in the documentation:qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DMySQL_INCLUDE_DIR="C:\mysql-8.0.22-winx64\include" -DMySQL_LIBRARY="C:\mysql-8.0.22-winx64\lib\libmysql.lib"
So, did you do this?
And one more question: when do you get this plug-in not loaded error: when you start your app from QtCreator or after deployment?
-
@Cervo2paille said in QSqlDatabase: MYSQL driver not loaded:
I tried... and got the same error, again. :)
What exactly did you try?
You need to install MariaDB C Connector before you build the plug-in. And then you pass the paths to the CMake call like shown in the documentation:qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>\<platform> -DMySQL_INCLUDE_DIR="C:\mysql-8.0.22-winx64\include" -DMySQL_LIBRARY="C:\mysql-8.0.22-winx64\lib\libmysql.lib"
So, did you do this?
And one more question: when do you get this plug-in not loaded error: when you start your app from QtCreator or after deployment?
@jsulm You're right i got a problem on this line.
I addapted to my system :qt-cmake -G Ninja D:\Qt\6.3.1\mingw_64\bin -DCMAKE_INSTALL_PREFIX="D:\Qt\6.3.1\mingw_64" -DMySQL_INCLUDE_DIR="D:\Program Files\MySQL\MySQL Server 8.0\include" -DMySQL_LIBRARY="D:\Program Files\MySQL\MySQL Server 8.0\lib\libmysql.lib"
But i got a
'qt-cmake' is not recognized as an internal command or external, an executable program or a batch file.
I installed it , during the installation accepted to add to my Windows path the cmake... but it didn't worked.
Thank you for your time
-
@jsulm You're right i got a problem on this line.
I addapted to my system :qt-cmake -G Ninja D:\Qt\6.3.1\mingw_64\bin -DCMAKE_INSTALL_PREFIX="D:\Qt\6.3.1\mingw_64" -DMySQL_INCLUDE_DIR="D:\Program Files\MySQL\MySQL Server 8.0\include" -DMySQL_LIBRARY="D:\Program Files\MySQL\MySQL Server 8.0\lib\libmysql.lib"
But i got a
'qt-cmake' is not recognized as an internal command or external, an executable program or a batch file.
I installed it , during the installation accepted to add to my Windows path the cmake... but it didn't worked.
Thank you for your time
@Cervo2paille said in QSqlDatabase: MYSQL driver not loaded:
I installed it , during the installation accepted to add to my Windows path the cmake
qt_cmake should be part of your Qt installation, simply use full path to it.
-
Thanks
But here we go again
The 3 files are inside the project, where the documentation wants me to do :
MSVC runtime is installed.
Maybe the problem come from the commands... i can see if they where well executed.
Near to success... bot not yet.
Thanks. -
Thanks
But here we go again
The 3 files are inside the project, where the documentation wants me to do :
MSVC runtime is installed.
Maybe the problem come from the commands... i can see if they where well executed.
Near to success... bot not yet.
Thanks.@Cervo2paille I think you must include the exe folder path in environmental "Path" variable
-
Thanks
But here we go again
The 3 files are inside the project, where the documentation wants me to do :
MSVC runtime is installed.
Maybe the problem come from the commands... i can see if they where well executed.
Near to success... bot not yet.
Thanks.@Cervo2paille It looks like it is actually working? You just messed up with connections.
-
This post is deleted!
-
@Cervo2paille It looks like it is actually working? You just messed up with connections.
@jsulm Added Cmake Path and retry the commands. In fact, the commands seems to not be passed because here, they gave me an error :
C:\Users\flebourgeois\build-sqldrivers>qt-cmake -G Ninja D:\Users\flebourgeois\Documents\QT_Projets\blossom -DCMAKE_INSTALL_PREFIX="D:\Qt\6.3.1\mingw_64" -DMySQL_INCLUDE_DIR="D:\Program Files\MySQL\MySQL Server 8.0\include" -DMySQL_LIBRARY="D:\Program Files\MySQL\MySQL Server 8.0\lib\libmysql.lib" CMake Error: CMake was unable to find a build program corresponding to "Ninja". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool. CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage -- Configuring incomplete, errors occurred!
Tried to Install Ninja on my windows Ninja.
Config of my project under QT :
Maybe my -DCMAKE_INSTALL_PREFIX isn't ok ?
My CMAKE_MAKE_PROGRAM in QT show me a Ninja.exe, it's not ok ?
Thanks for your help :) -
Hi, you can also try without the
-G Ninja
stuff, e.g.C:\Users\flebourgeois\build-sqldrivers>qt-cmake D:\Users\flebourgeois\Documents\Q...
@hskoglund Hey, thanks i successful to do the commands. But i got again and again the same error.
The installation :D:\Users\fabdu\Documents\build-blossom-Desktop_Qt_6_3_1_MinGW_64_bit-Debug>qt-cmake -G Ninja "D:\Users\fabdu\Documents\blossom" -DCMAKE_INSTALL_PREFIX="D:\Qt\6.3.1\mingw_64" -DMySQL_INCLUDE_DIR="D:\Program Files (x86)\MySQL\MySQL Server 5.5\include" -DMySQL_LIBRARY="D:\Program Files (x86)\MySQL\MySQL Server 5.5\lib\libmysql.lib" -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) -- Configuring done -- Generating done CMake Warning: Manually-specified variables were not used by the project: CMAKE_TOOLCHAIN_FILE MySQL_INCLUDE_DIR MySQL_LIBRARY -- Build files have been written to: D:/Users/fabdu/Documents/build-blossom-Desktop_Qt_6_3_1_MinGW_64_bit-Debug D:\Users\fabdu\Documents\build-blossom-Desktop_Qt_6_3_1_MinGW_64_bit-Debug>cmake --build . ninja: no work to do. D:\Users\fabdu\Documents\build-blossom-Desktop_Qt_6_3_1_MinGW_64_bit-Debug>cmake --install . -- Install configuration: "Debug" -- Installing: D:/Qt/6.3.1/mingw_64/bin/blossom.exe D:\Users\fabdu\Documents\build-blossom-Desktop_Qt_6_3_1_MinGW_64_bit-Debug>
The famous error :
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QPSQL
My Path :
I think i do a mistake about the starting of this line "qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers...".
What do you think about ? How to write it ?
If someone has an idea... thanks ! :) -
@hskoglund Hey, thanks i successful to do the commands. But i got again and again the same error.
The installation :D:\Users\fabdu\Documents\build-blossom-Desktop_Qt_6_3_1_MinGW_64_bit-Debug>qt-cmake -G Ninja "D:\Users\fabdu\Documents\blossom" -DCMAKE_INSTALL_PREFIX="D:\Qt\6.3.1\mingw_64" -DMySQL_INCLUDE_DIR="D:\Program Files (x86)\MySQL\MySQL Server 5.5\include" -DMySQL_LIBRARY="D:\Program Files (x86)\MySQL\MySQL Server 5.5\lib\libmysql.lib" -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) -- Configuring done -- Generating done CMake Warning: Manually-specified variables were not used by the project: CMAKE_TOOLCHAIN_FILE MySQL_INCLUDE_DIR MySQL_LIBRARY -- Build files have been written to: D:/Users/fabdu/Documents/build-blossom-Desktop_Qt_6_3_1_MinGW_64_bit-Debug D:\Users\fabdu\Documents\build-blossom-Desktop_Qt_6_3_1_MinGW_64_bit-Debug>cmake --build . ninja: no work to do. D:\Users\fabdu\Documents\build-blossom-Desktop_Qt_6_3_1_MinGW_64_bit-Debug>cmake --install . -- Install configuration: "Debug" -- Installing: D:/Qt/6.3.1/mingw_64/bin/blossom.exe D:\Users\fabdu\Documents\build-blossom-Desktop_Qt_6_3_1_MinGW_64_bit-Debug>
The famous error :
QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QPSQL
My Path :
I think i do a mistake about the starting of this line "qt-cmake -G Ninja <qt_installation_path>\Src\qtbase\src\plugins\sqldrivers...".
What do you think about ? How to write it ?
If someone has an idea... thanks ! :)@Cervo2paille I haved bat file for mariadb for WIndow if you want try.
-
thanks yes i would like to try :)
-
thanks yes i would like to try :)
@Cervo2paille
That is my bat for maria db tested on 5.15.2SET QTDIR="C:\Qt\5.15.2\Src"
SET MYSQL_INCDIR="C:\Program Files\MariaDB\MariaDB Connector C 64-bit\include"
SET MYSQL_LIBDIR="C:\Program Files\MariaDB\MariaDB Connector C 64-bit\lib"SET PATH=%PATH%;C:\Qt\5.15.2\mingw81_64\bin;C:\Qt\Tools\mingw810_64\bin;
cd %QTDIR%\qtbase\src\plugins\sqldrivers
pause
qmake -- MYSQL_INCDIR=%MYSQL_INCDIR% MYSQL_LIBDIR=%MYSQL_LIBDIR%
pause
mingw32-make sub-mysql
pause
mingw32-make install
pause1.Before build, clear the previous installation
2. copy libmariadb in exe directoryI hose it is useful.
The driver installed for Maria DB is "C Connector".