Partage
  • Partager sur Facebook
  • Partager sur Twitter

Qt MySQL - Problème de driver non chargé

Qt MySQL - Problème de driver non chargé

    4 avril 2024 à 9:53:31



    Bonjour,

    Je suis sur ce problème depuis 2 jours et je suis aujourd'hui incapable de trouver la solution. J'espère que vous pourrez me donner un petit coup de main.

    Je souhaite faire communiquer mon programme Qt avec une bdd MySQL sous WAMP.

    Voici le code sous Qt responsable de la connexion:

       
    bool SQLManagement::createConnection(){
        qDebug() << QSqlDatabase::drivers() << "\n"; // Affichage des modules activés
     
        _database = QSqlDatabase::addDatabase("QMYSQL"); // Type de database que je souhaite utiliser
        _database.setHostName("localhost:3306");
        _database.setDatabaseName("rfid");
        _database.setUserName("root");
        _database.setPassword("");
     
        if (!_database.open()) {
            qDebug() << _database.lastError();
            return false;
        }
     
        qDebug() << "Connected to the database successfully!";
        return true;
    }



    Lors de ma première tentative j'avais ce résultat dans le promp (affiché par la ligne QSqlDatabase::drivers() )

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QMIMER QMARIADB QPSQL
    QSqlError("", "Driver not loaded", "Driver not loaded")



    J'ai donc suivi les nombreux tutos sur internet pour ajouter ce driver. J'ai donc télécharger les sources de Qt (https://download.qt.io/archive/qt/) avec la version qui correspond à mon dossier Qt (C:\Qt\6.6.2).

    J'ai ensuite executer ces commandes comme indiqué sur le site (https://doc.qt.io/qt-6/sql-driver.html#qmysql)
     
      
    mkdir build-sqldrivers
    cd build-sqldrivers
    C:\Qt\6.6.2\mingw_64\bin\qt-cmake -G Ninja C:\Qt\6.6.2\qt-everywhere-src-6.6.2\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX="C:\Qt\6.6.2\mingw_64" -DMySQL_INCLUDE_DIR="C:\wamp64\bin\mysql\mysql8.2.0\include" -DMySQL_LIBRARY="C:\wamp64\bin\mysql\mysql8.2.0\lib\libmysql.lib"<br>cmake --build .
    cmake --install .


    Et voici le resultat du cmd:
        
    C:\Users\X\Desktop\dr>C:\Qt\6.6.2\mingw_64\bin\qt-cmake -G Ninja C:\Qt\6.6.2\qt-everywhere-src-6.6.2\qtbase\src\plugins\sqldrivers -DCMAKE_INSTALL_PREFIX="C:\Qt\6.6.2\mingw_64" -DMySQL_INCLUDE_DIR="C:\wamp64\bin\mysql\mysql8.2.0\include" -DMySQL_LIBRARY="C:\wamp64\bin\mysql\mysql8.2.0\lib\libmysql.lib"
    -- The CXX compiler identification is GNU 13.2.0
    -- The C compiler identification is GNU 13.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: C:/Program Files/mingw64/bin/gcc.exe
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: C:/Program Files/mingw64/bin/c++.exe - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: C:/Program Files/mingw64/bin/gcc.exe - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
    -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
    -- Found Threads: TRUE
    -- Performing Test HAVE_STDATOMIC
    -- Performing Test HAVE_STDATOMIC - Success
    -- Found WrapAtomic: TRUE
    -- CMAKE_BUILD_TYPE was set to: 'RelWithDebInfo'
     
    -- Configuration summary shown below. It has also been written to C:/Users/X/Desktop/dr/config.summary
    -- Configure with --log-level=STATUS or higher to increase CMake's message verbosity. The log level does not persist across reconfigurations.
     
    -- Configure summary:
     
    Qt Sql Drivers:
      DB2 (IBM) .............................. no
      InterBase .............................. no
      MySql .................................. yes
      OCI (Oracle) ........................... no
      ODBC ................................... yes
      PostgreSQL ............................. no
      SQLite ................................. yes
        Using system provided SQLite ......... no
      Mimer .................................. no
     
     
    -- Configuring done (3.6s)
    -- Generating done (0.1s)
    -- Build files have been written to: C:/Users/X/Desktop/dr
     
    C:\Users\X\Desktop\dr>cmake --build .
    [25/25] Linking CXX shared module plugins\sqldrivers\qsqlite.dll
     
    C:\Users\X\Desktop\dr>cmake --install .
    -- Install configuration: "RelWithDebInfo"
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginConfig.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginConfigVersion.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginConfigVersionImpl.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/./plugins/sqldrivers/qsqlmysql.dll
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginTargets.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginTargets-relwithdebinfo.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/./plugins/sqldrivers/qsqlmysql.debug
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginAdditionalTargetInfo.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QODBCDriverPluginConfig.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QODBCDriverPluginConfigVersion.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QODBCDriverPluginConfigVersionImpl.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/./plugins/sqldrivers/qsqlodbc.dll
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QODBCDriverPluginTargets.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QODBCDriverPluginTargets-relwithdebinfo.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/./plugins/sqldrivers/qsqlodbc.debug
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QODBCDriverPluginAdditionalTargetInfo.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QSQLiteDriverPluginConfig.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QSQLiteDriverPluginConfigVersion.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QSQLiteDriverPluginConfigVersionImpl.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/./plugins/sqldrivers/qsqlite.dll
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QSQLiteDriverPluginTargets.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QSQLiteDriverPluginTargets-relwithdebinfo.cmake
    -- Installing: C:/Qt/6.6.2/mingw_64/./plugins/sqldrivers/qsqlite.debug
    -- Installing: C:/Qt/6.6.2/mingw_64/lib/cmake/Qt6Sql/Qt6QSQLiteDriverPluginAdditionalTargetInfo.cmake
     
    C:\Users\X\Desktop\dr>


    Lorsque je relance Qt avec mon programme, j'ai maitenant ce résultat:

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMIMER QMARIADB QMYSQL QODBC QPSQL
    QSqlError("", "Driver not loaded", "Driver not loaded")


    Donc visiblement, Qt à bien chargé la .dll QMYSQL. J'obtiens cependant toujours l'erreur "QMYSQL driver not loaded".

    J'ai bien évidemment mis le "libmysql.dll" avec le .exe, mais j'ai toujours le même probléme, càd un beau "QMYSQL driver not loaded".

    J'ai essayé les étapes ci-dessus avec MAMP ; en téléchargeant directement libmysql.dll sur internet ; directement avec le miroir mysql (https://dev.mysql.com/downloads/installer/)

    Toujours le même problème malheuresement...

    N'hesitez pas si vous avez déjà rencontré ce problème.
    Je vous remercie d'avance pour votre aide.


    • Partager sur Facebook
    • Partager sur Twitter

    Qt MySQL - Problème de driver non chargé

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    • Editeur
    • Markdown