Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qtcreator 32bit and mysql 8.0 64bit



  • Hello everyone ,
    I am a novice in development Qt. I have to download the opensource version of Qt to train on this framework that I find complete and pretty!
    I made myself a small database of 3 tables to train the relationship N to M. The only problem is that I can not load the MYSQL driver. I refer to Qt's documentation here
    https://doc.qt.io/qt-5/sql-driver.html
    It is put that it is necessary to compile the drivers because there are problems of compatibility of license.

    According to the documentation, I have to make this command

    cd $QTDIR/qtbase/src/plugins/sqldrivers
    

    Except this command does not work because the path does not exist. Do I have to create it? And if yes, how?
    Because I do not even have the qbase folder. I try several things that I find on the internet like download mysql.dll .dll and mysqld.dll and put them in the built executable folder.
    I made a little code that tests the connection to the database here.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
     
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
     
    MainWindow::~MainWindow()
    {
        delete ui;
    }
     
     
    void MainWindow::on_pushButton_clicked()
    {
        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("localhost");
        db.setDatabaseName("entreprise");
        db.setUserName("root");
        db.setPassword("pass");
     
        if(db.open()){
            QMessageBox::information(this,"Connection","Database connected");
        }
        else{
            QMessageBox::warning(this,"Not Connected", "not connected");
        }
    }
    

    When the compilation works. Once I press the button. I have the following errors that appear

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
    

    Ideas ? Thank you :)


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Use the Maintenance Tool and download the Qt sources from there.



  • Thanks for the welcome :)
    I have the maintenance tool. I choose to add a component.
    I already checked Qt5.12.5.
    And I chose in the tools of development and designer:
    Qt creator 4.10.1 CDB Debugger Support
    Debugging tools for windows
    MinGW 7.3.0 32bit and 64bit.
    Should I take something else?

    To come back to the problem, I ended up finding the file

    C:\Qt\5.12.5\Src\qtbase\src\plugins\sqldrivers
    

    Then I added the qmake to the PATH, to execute the command

    qmake -- MYSQL_INCDIR=C:/Program Files/MySQL/include "MYSQL_LIBDIR=C:/Program Files/MySQL/MySQL Server 8.0/lib/opt"
    

    An error appears

    ERROR: Invalid command line parameter 'Files/MySQL/include'.
    

    Because I do not have a folder, the folder includes, is located in the 8.0 server folder and 8.0 c ++ connector
    Which one should I use. The command of the documentation is this one

    qmake -- MYSQL_INCDIR=C:/MySQL/include "MYSQL_LIBDIR=C:/MYSQL/MySQL Server <version>/lib/opt"
    

    I ask myself another question. What is the "opt" at the end of the order. Because in my file
    C: \ Program Files \ MySQL \ MySQL Server 8.0 \ lib
    there is no "opt" file
    Thank you for helping me :)



  • To finish I have a result. it goes slowly :)
    Here is the result

    C:\Qt\5.12.5\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR=C:/"Program Files"/MySQL/include "MYSQL_LIBDIR=C:/Program Files/MySQL/MySQL Server 8.0/lib/opt"
    
    Running configuration tests...
    Done running configuration tests.
    
    Configure summary:
    
    Qt Sql Drivers:
      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, you must run 'mingw32-make install'.
    Qt will be installed into 'C:\Qt\5.12.5\mingw73_32'.
    
    Prior to reconfiguration, make sure you remove any leftovers from
    the previous build.
    
    
    C:\Qt\5.12.5\Src\qtbase\src\plugins\sqldrivers>mingw32-make install
    cd odbc\ && ( if not exist Makefile C:\Qt\5.12.5\mingw73_32\bin\qmake.exe -o Makefile C:\Qt\5.12.5\Src\qtbase\src\plugins\sqldrivers\odbc\odbc.pro ) && mingw32-make -f Makefile install
    mingw32-make[1]: Entering directory 'C:/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/odbc'
    mingw32-make -f Makefile.Release install
    mingw32-make[2]: Entering directory 'C:/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/odbc'
    copy /y ..\plugins\sqldrivers\qsqlodbc.dll C:\Qt\5.12.5\mingw73_64\plugins\sqldrivers\qsqlodbc.dll
            1 fichier(s) copié(s).
    C:\Qt\5.12.5\mingw73_64\bin\qmake.exe -install qinstall C:\Qt\5.12.5\Src\qtbase\src\plugins\sqldrivers\lib\cmake\Qt5Sql\Qt5Sql_QODBCDriverPlugin.cmake C:\Qt\5.12.5\mingw73_64\lib\cmake\Qt5Sql\Qt5Sql_QODBCDriverPlugin.cmake
    mingw32-make[2]: Leaving directory 'C:/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/odbc'
    mingw32-make -f Makefile.Debug install
    mingw32-make[2]: Entering directory 'C:/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/odbc'
    copy /y ..\plugins\sqldrivers\qsqlodbcd.dll C:\Qt\5.12.5\mingw73_64\plugins\sqldrivers\qsqlodbcd.dll
            1 fichier(s) copié(s).
    C:\Qt\5.12.5\mingw73_64\bin\qmake.exe -install qinstall C:\Qt\5.12.5\Src\qtbase\src\plugins\sqldrivers\lib\cmake\Qt5Sql\Qt5Sql_QODBCDriverPlugin.cmake C:\Qt\5.12.5\mingw73_64\lib\cmake\Qt5Sql\Qt5Sql_QODBCDriverPlugin.cmake
    mingw32-make[2]: Leaving directory 'C:/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/odbc'
    mingw32-make[1]: Leaving directory 'C:/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/odbc'
    cd sqlite\ && ( if not exist Makefile C:\Qt\5.12.5\mingw73_32\bin\qmake.exe -o Makefile C:\Qt\5.12.5\Src\qtbase\src\plugins\sqldrivers\sqlite\sqlite.pro ) && mingw32-make -f Makefile install
    mingw32-make[1]: Entering directory 'C:/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/sqlite'
    mingw32-make -f Makefile.Release install
    mingw32-make[2]: Entering directory 'C:/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/sqlite'
    copy /y ..\plugins\sqldrivers\qsqlite.dll C:\Qt\5.12.5\mingw73_64\plugins\sqldrivers\qsqlite.dll
            1 fichier(s) copié(s).
    C:\Qt\5.12.5\mingw73_64\bin\qmake.exe -install qinstall C:\Qt\5.12.5\Src\qtbase\src\plugins\sqldrivers\lib\cmake\Qt5Sql\Qt5Sql_QSQLiteDriverPlugin.cmake C:\Qt\5.12.5\mingw73_64\lib\cmake\Qt5Sql\Qt5Sql_QSQLiteDriverPlugin.cmake
    mingw32-make[2]: Leaving directory 'C:/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/sqlite'
    mingw32-make -f Makefile.Debug install
    mingw32-make[2]: Entering directory 'C:/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/sqlite'
    copy /y ..\plugins\sqldrivers\qsqlited.dll C:\Qt\5.12.5\mingw73_64\plugins\sqldrivers\qsqlited.dll
            1 fichier(s) copié(s).
    C:\Qt\5.12.5\mingw73_64\bin\qmake.exe -install qinstall C:\Qt\5.12.5\Src\qtbase\src\plugins\sqldrivers\lib\cmake\Qt5Sql\Qt5Sql_QSQLiteDriverPlugin.cmake C:\Qt\5.12.5\mingw73_64\lib\cmake\Qt5Sql\Qt5Sql_QSQLiteDriverPlugin.cmake
    mingw32-make[2]: Leaving directory 'C:/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/sqlite'
    mingw32-make[1]: Leaving directory 'C:/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/sqlite'
    

    MySql is not ok. Maybe one idea?
    I can read

    mingw32-make[1]: Entering directory 'C:/Qt/5.12.5/Src/qtbase/src/plugins/sqldrivers/odbc'
    

    Why dont entering in the existing directory

    C:\Qt\5.12.5\Src\qtbase\src\plugins\sqldrivers\mysql
    

    Maybe the command


  • Lifetime Qt Champion

    Check the logs, you'll se why the test failed for MySQL.



  • What log do you speak ?
    A command or a way of doing? I'm a beginner :)


  • Lifetime Qt Champion

    Check for a folder name config.tests and look its content.

    I would use grep or ag for that but I am not sure you have these commands available on your Windows machine.



  • I dont fine the file config.tests. Where is it ? In Qt or Mysql? i try that

    @echo off
    echo Setting up environment forQt usage...
    
    set QTDIR=C:\Qt\qt 5.10.1\5.10.1\migw53_32
    set MINGW=C:\Qt\qt 5.10.1\Tools\mingw530_32
    set MYSQLCONNECTORDIR=C:\Qt\qt 5.10.1\MYSQL
    
    echo Download mysql connector
    mkdir %MYSQLCONNECTORDIR%
    cd %MYSQLCONNECTORDIR%
    powershell -Command"Invoke-WebRequest https://dev.mysql.com/get/Downloads/Connector-C/mysql-connector-c-6.1.11-win32.zip -OutFile mysql-connector-c-6.1.11-win32.zip"
    unzip -d mysql-connector-c-6.1.11-win32.zip
    powershell.exe -nologo -noprofile -command "& { $shell = New-Object -COM Shell.Application; $target = $shell.NameSpace($env:MYSQLCONNECTORDIR); $zip = $shell.NameSpace($env:MYSQLCONNECTORDIR + '\mysql-connector-c-6.1.11-win32.zip'); $target.CopyHere($zip.Items(), 16); }"
    
    set PATH=%QTDIR%\bin;%MINGW%\bin;%PATH%
    cd /D %QTDIR%
    cd ..\Src\qtbase\src\plugins\sqldrivers\mysql
    qmake -- MYSQL_INCDIR=%MYSQLCONNECTORDIR%\include "MYSQL_LIBDIR=%MYSQLCONNECTORDIR%\lib"
    qmake "INCLUDEPATH+=%MYSQLCONNECTORDIR%\\mysql-connector-c-6.1.11-win32\\include""LIBS+=%MYSQLCONNECTORDIR%\\mysql-connector-c-6.1.11-win32\\lib\\libmysql.lib" mysql.pro
    mingw32-make
    mingw32-make install
    

    But not work... I dont have qsqmysql.dll
    have an idea?


  • Lifetime Qt Champion

    What kind of terminal are you using ?



  • @Raftapss
    cmd
    but i have a resutat. In the qt the compilator when i try mysql with just a connect

    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
    

    Now i have the QMYSQL in avaible drivers, but i dont have the driver i dont anderstand[link text]


  • Lifetime Qt Champion

    See for example https://forum.qt.io/topic/107997/qt-win10-qmysql-driver-not-loaded or use the forum search function


Log in to reply