0

I Use My SQL and i developped my application on QT. I see many answer about my question but, the question was old and, i have an other probleme less speake.

my code it's just this :

#include <stdlib.h>
#include <stdio.h>

#include <QtSql>

int main(int argc, char *argv[])
{
    printf("Hello wordl ! \n");

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("meropyDatabase");
    db.setUserName("User");
    db.setPassword("ApplicationUser21!");
    bool ok = db.open();

    printf("Data base : %d \n",ok);

    //QSqlQuery query;
    db.exec("INSERT INTO Users (FirstName,LastName,IDCompany,EmailAddress) VALUES ('Jean','MICKEL',1,'jean.mickel@hotmail.fr')");


    printf("erreur : %s \n",db.lastError().text().toStdString().c_str());
    return 0;
}

And i have this error message :

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
QSqlQuery::exec: database not open
Hello wordl ! 
Data base : 0 
erreur : Driver not loaded Driver not loaded 

Today, i don't understand what make i for take work this...

For the option available drivers MYSQL is not here I try to add different dll but not change....

I have juste change when i use QSQLITE but, it's connect on my database but it's don't find the table...

i use QT 5.15 and MySQL 8.0

In try to test this tuto : https://doc.qt.io/qt-5/sql-driver.html for window, the first step it's ok, i discover the correcly directory, But, for the second step : "qmake MYSQL_INCDIR="C:\Program Files\MySQL\Connector C++ 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\Connector C++ 8.0\lib64""

I have this message:

Running configuration tests...
Done running configuration tests.

Configure summary:

Qt Sql Drivers:
  DB2 (IBM) .............................. no
  InterBase .............................. no
  MySql .................................. no
  OCI (Oracle) ........................... no
  ODBC ................................... no
  PostgreSQL ............................. no
  SQLite2 ................................ no
  SQLite ................................. yes
    Using system provided SQLite ......... no
  TDS (Sybase) ........................... no

Qt is now configured for building. Just run 'nmake'.
Once everything is built, you must run 'nmake install'.
Qt will be installed into 'C:\Qt\5.15.2\msvc2019_64'.

Prior to reconfiguration, make sure you remove any leftovers from
the previous build.

and nmake or mingw32-make don't work for n make i have this error :

rc /NOLOGO -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DQT_NO_LINKED_LIST -DQT_NO_JAVA_STYLE_ITERATORS -DNDEBUG -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_OMIT_COMPLETE -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_JSON1 -DSQLITE_OMIT_LOAD_EXTENSION -DQT_DEPRECATED_WARNINGS -DQT_NO_NARROWING_CONVERSIONS_IN_CONNECT -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DNDEBUG -DQT_NO_EXCEPTIONS -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -D_WINDLL -fo .obj\release\qsqlite_resource.res qsqlite_resource.rc
qsqlite_resource.rc(1) : fatal error RC1015: cannot open include file 'windows.h'.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\rc.EXE"' : code retour '0x1'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\Hostx64\x64\nmake.exe"' : code retour '0x2'
Stop.
NMAKE : fatal error U1077: 'cd' : code retour '0x2'
Stop.

En effect, i don't find the file windows.h or the other file for QT...

vin212
  • 7
  • 2
  • This document explains what you need to do: [https://doc.qt.io/qt-5/sql-driver.html](https://doc.qt.io/qt-5/sql-driver.html) – drescherjm Jan 20 '22 at 15:17
  • 1
    this might help you too: https://stackoverflow.com/q/42683438/982161 – ΦXocę 웃 Пepeúpa ツ Jan 20 '22 at 15:19
  • it's for old version, i try but it's don't work (and for different example i don't have the files) – vin212 Jan 20 '22 at 15:30
  • The procedure is basically the same regardless of the Qt version. You need to obtain the files both the Qt source files and your mysql source code for the mysql connector and build according to the Qt documentation. – drescherjm Jan 20 '22 at 16:06
  • Ok, i try, but i have an error "acces denied" – vin212 Jan 20 '22 at 16:21
  • You will have to figure out the permissions problem with your OS file explorer. Also make sure you are not attempting to build inside of C:\Program Files. And avoid the temptation to use "Run As Administrator" while building. – drescherjm Jan 20 '22 at 16:30
  • i change the autorization but not more, i have the same error message : "qmake MYSQL_INCDIR = "C:\Program Files\MySQL\Connector C++ 8.0\include" MYSQL_LIBDIR = "C:\Program Files\MySQL\Connector C++ 8.0\lib64"" – vin212 Jan 20 '22 at 16:39
  • You probably should edit your question. And add the full output. I see no problem in the contents of the previous comment. – drescherjm Jan 20 '22 at 16:42
  • ***and nmake or mingw32-make don't work (i don't have this programme)*** Depending on what compiler you are using you should have one of these. If you are using msvc you should have nmake. If you are using mingw you should have mingw32-make. You probably are not compiling from a command prompt that has the PATH and other environment variables properly setup for the compiler you are using. – drescherjm Jan 20 '22 at 17:13

0 Answers0