Connect Qt to MySQL



  • I'm trying to connect Qt and MySQL,
    But i can't build the .dll as explain in the documentation : the lines
    cd %QTDIR%\src\plugins\sqldrivers\mysql

    qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MYSQL\MySQL Server <version>\lib\opt\libmysql.lib" mysql.pro
    nmake
    

    gives me :
    cannot find mysql.pro
    I'm on Windows 10...



  • Check sources path
    example:

    cd C:\qt-everywhere-opensource-src-5.6.0\qt-everywhere-opensource-src-5.6.0\qtbase\src\plugins\sqldrivers\mysql
    qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MySQL\lib\libmysql.lib" mysql.pro
    nmake
    nmake install
    


  • Do you mean that the folder src\plugins\sqldrivers\mysql must contains "mysql.pro" ?
    And i've got no folder named qtbase in my Qt folder



  • @Detordreur said:

    Do you mean that the folder src\plugins\sqldrivers\mysql must contains "mysql.pro" ?

    Yes

    for example:

    1. Download.
      http://download.qt.io/official_releases/qt/5.6/5.6.0/single/qt-everywhere-opensource-src-5.6.0.zip
    2. Unpack.
    3. Find "mysql.pro" on ...your path...\qt-everywhere-opensource-src-5.6.0\qtbase\src\plugins\sqldrivers\mysql


  • You are my hero !
    But it still don't work, when i run nmake, I get this :

    Setting up environment for Qt usage...
    'MySQL' n’est pas reconnu en tant que commande interne
    ou externe, un programme exécutable ou un fichier de commandes.
    'MySQL' n’est pas reconnu en tant que commande interne
    ou externe, un programme exécutable ou un fichier de commandes.
    
    C:\Qt\5.5\mingw492_32>cd C:\qt-everywhere-opensource-src-5.6.0\qtbase\src\plugins\sqldrivers\mysql
    
    C:\qt-everywhere-opensource-src-5.6.0\qtbase\src\plugins\sqldrivers\mysql>qmake "INCLUDEPATH+=C:\Program Files\MySQL\MySQL Server 5.7\include" "LIBS+=C:\Program Files\MySQL\MySQL Server 5.7\lib\libmysql.lib" mysql.pro
    
    C:\qt-everywhere-opensource-src-5.6.0\qtbase\src\plugins\sqldrivers\mysql>set PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
    
    C:\qt-everywhere-opensource-src-5.6.0\qtbase\src\plugins\sqldrivers\mysql>nmake
    
    Microsoft (R) Program Maintenance Utility Version 14.00.23918.0
    Copyright (C) Microsoft Corporation. Tous droits réservés.
    
            "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\nmake.exe" -f Makefile.Release all
    
    Microsoft (R) Program Maintenance Utility Version 14.00.23918.0
    Copyright (C) Microsoft Corporation. Tous droits réservés.
    
            g++ -c -pipe -fno-keep-inline-dllexport -Is:/include -O2 -std=c++0x -std=c++0x -fno-exceptions -frtti -Wall -Wextra -DUNICODE -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -IC:/Utils/icu32_54_1_mingw492/include -IC:/openssl/include -IC:/utils/postgresql/pgsql/include -IC:\Program -IFiles\MySQL\MySQL -IServer -I5.7\include -IC:\Qt\5.5\mingw492_32\include\QtCore\5.5.1 -IC:\Qt\5.5\mingw492_32\include\QtCore\5.5.1\QtCore -IC:\Qt\5.5\mingw492_32\include\QtSql\5.5.1 -IC:\Qt\5.5\mingw492_32\include\QtSql\5.5.1\QtSql -IC:\Qt\5.5\mingw492_32\include -IC:\Qt\5.5\mingw492_32\include\QtSql -IC:\Qt\5.5\mingw492_32\include\QtCore -I.moc\release -I..\..\..\..\mkspecs\win32-g++ -o .obj\release\main.o main.cpp
    In file included from main.cpp:36:0:
    ../../../sql/drivers/mysql/qsql_mysql_p.h:55:19: fatal error: mysql.h: No such file or directory
     #include <mysql.h>
                       ^
    compilation terminated.
    NMAKE : fatal error U1077: 'C:\Qt\Tools\mingw492_32\bin\g++.EXE' : code retour '0x1'
    Stop.
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\nmake.exe"' : code retour '0x2'
    Stop.
    
    C:\qt-everywhere-opensource-src-5.6.0\qtbase\src\plugins\sqldrivers\mysql>
    


  • Set environment variable for mysql and use paths without spaces:
    "INCLUDEPATH+=C:\Program Files\MySQL\MySQL Server 5.7\include" "LIBS+=C:\Program Files\MySQL\MySQL Server 5.7\lib\libmysql.lib"
    must be like this:
    C:\PROGRA~2\MySQL\MYSQLS~1.5
    also, you using mingw or VC compiler?
    Try this manual(MinGW):
    http://seppemagiels.com/blog/create-mysql-driver-qt5-windows



  • I've tried with both.
    This manual gives me a different error :

    C:\qt-everywhere-opensource-src-5.6.0\qtbase\src\plugins\sqldrivers\mysql>mingw32-make
    mingw32-make -f Makefile.Release all
    mingw32-make[1]: Entering directory 'C:/qt-everywhere-opensource-src-5.6.0/qtbase/src/plugins/sqldrivers/mysql'
    g++ -c -pipe -fno-keep-inline-dllexport -Is:/include -O2 -std=c++0x -std=c++0x -fno-exceptions -frtti -Wall -Wextra -DUNICODE -DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_EXCEPTIONS -DQT_NO_DEBUG -DQT_PLUGIN -DQT_SQL_LIB -DQT_CORE_LIB -I. -IC:/Utils/icu32_54_1_mingw492/include -IC:/openssl/include -IC:/utils/postgresql/pgsql/include -IC:\PROGRA~2\MySQL\MYSQLS~1.5\include -IC:\Qt\5.5\mingw492_32\include\QtCore\5.5.1 -IC:\Qt\5.5\mingw492_32\include\QtCore\5.5.1\QtCore -IC:\Qt\5.5\mingw492_32\include\QtSql\5.5.1 -IC:\Qt\5.5\mingw492_32\include\QtSql\5.5.1\QtSql -IC:\Qt\5.5\mingw492_32\include -IC:\Qt\5.5\mingw492_32\include\QtSql -IC:\Qt\5.5\mingw492_32\include\QtCore -I.moc\release -I..\..\..\..\mkspecs\win32-g++  -o .obj\release\main.o main.cpp
    In file included from main.cpp:36:0:
    ../../../sql/drivers/mysql/qsql_mysql_p.h:55:19: fatal error: mysql.h: No such file or directory
     #include <mysql.h>
                       ^
    compilation terminated.
    Makefile.Release:478: recipe for target '.obj/release/main.o' failed
    mingw32-make[1]: *** [.obj/release/main.o] Error 1
    mingw32-make[1]: Leaving directory 'C:/qt-everywhere-opensource-src-5.6.0/qtbase/src/plugins/sqldrivers/mysql'
    makefile:38: recipe for target 'release-all' failed
    mingw32-make: *** [release-all] Error 2
    


  • Can you share your paths "INCLUDEPATH+=" "LIBS+=" at this line:
    qmake "INCLUDEPATH+=C:\MySQL\include" "LIBS+=C:\MySQL\lib\libmysql.lib" mysql.pro



  • Yes sure :
    I tried this :
    set mysql=C:\PROGRA~2\MySQL\MYSQLS~1.5
    and
    set mysql=C:\Program Files\MySQL\MySQL Server 5.7

    then
    "INCLUDEPATH+=%mysql%include... etc

    the two solutions gives me the same error :

    compilation terminated.
    Makefile.Release:478: recipe for target '.obj/release/main.o' failed
    mingw32-make[1]: *** [.obj/release/main.o] Error 1
    mingw32-make[1]: Leaving directory 'C:/qt-everywhere-opensource-src-5.6.0/qtbase/src/plugins/sqldrivers/mysql'
    makefile:38: recipe for target 'release-all' failed
    mingw32-make: *** [release-all] Error 2

    I have no folder in C named Mysql, maybe I miss some librairies for MySQL, but I made the complete installation... I don't know ?


  • Moderators

    Try with:

    set mysql="C:\Program Files\MySQL\MySQL Server 5.7"
    


  • This post is deleted!


  • It give me :

    Cannot find file: Files\MySQL\MySQL.
    Cannot find file: Server.
    Cannot find file: 5.7\include.
    Cannot find file: Files\MySQL\MySQL.
    Cannot find file: Server.
    Cannot find file: 5.7\lib\libmysql.lib.
    Cannot find file: mysql.pro.
    

    I don't understand the line "Mysql.h : no such file or directory" in the error text, there is in fact a file named mysql.h in my folder "MySQL server 5.7\include"


  • Lifetime Qt Champion

    Hi,

    The best thing to do is to move your MySQL installation in a folder without any space in the path. Or use the 8.3 notation.



  • I did it, it resolved my first error, but it gives me a new one :

    My lines :

    cd C:\qt-everywhere-opensource-src-5.6.0\qtbase\src\plugins\sqldrivers\mysql
    set mysql=C:\MySQL\MySQL_Server_5.7
    qmake "INCLUDEPATH+=%mysql%\include" "LIBS+=%mysql%\lib\libmysql.lib" mysql.pro
    mingw32-make
    

    And the error :

    mingw32-make[1]: Entering directory 'C:/qt-everywhere-opensource-src-5.6.0/qtbase/src/plugins/sqldrivers/mysql'
    g++ -Wl,-s -shared -Wl,-subsystem,windows -Wl,--out-implib,C:\qt-everywhere-opensource-src-5.6.0\qtbase\plugins\sqldrivers\libqsqlmysql.a -o ..\..\..\..\plugins\sqldrivers\qsqlmysql.dll .obj/release/main.o .obj/release/qsql_mysql.o .obj/release/moc_qsql_mysql_p.o  C:\MySQL\MySQL_Server_5.7\lib\libmysql.lib -LC:/Qt/5.4/mingw491_32/lib -lQt5Sql542 -lQt5Core542 .obj\release\qsqlmysql_resource_res.o
    C:/Qt/Tools/mingw491_32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lQt5Sql542
    C:/Qt/Tools/mingw491_32/bin/../lib/gcc/i686-w64-mingw32/4.9.1/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lQt5Core542
    collect2.exe: error: ld returned 1 exit status
    Makefile.Release:81: recipe for target '..\..\..\..\plugins\sqldrivers\qsqlmysql.dll' failed
    mingw32-make[1]: *** [..\..\..\..\plugins\sqldrivers\qsqlmysql.dll] Error 1
    mingw32-make[1]: Leaving directory 'C:/qt-everywhere-opensource-src-5.6.0/qtbase/src/plugins/sqldrivers/mysql'
    makefile:38: recipe for target 'release-all' failed
    mingw32-make: *** [release-all] Error 2
    Appuyez sur une touche pour continuer...
    

  • Lifetime Qt Champion

    Looks like you are trying to build the Qt 5.6.0 sources with Qt 5.4.2 ?



  • Yes, I was, so I reinstall Qt 5.6, finally, and I get a (last?) error : The compiler is MSVC 2015, but at the line "nmake", i get a invalid command error
    So I tried to call vcvarsall.bat, but I doesn't not change anything
    (Yes i'm really a beginner)


  • Moderators

    In your previous post I see: mingw32-make
    That means you was using MinGW. Did you switch to MSVC2015?
    Did you rerun qmake?



  • Yes I have, I desinstalled Qt 5.5, and reinstall Qt 5.6, and now the Qt console is name MSVC 2015, but it don't recognized the line "nmake"...
    Yes I rerun qmake


  • Lifetime Qt Champion

    Open a Visual Studio developer console, that will make thing easier. IIRC it should be in one of the subfolder of the Visual Studio Start menu entry.



  • I did it : qmake become invalid command, how do I set environnement to avoid it ?


  • Lifetime Qt Champion

    Either use the full path to qmake or go to the Qt folder and IIRC there's a qtvars.bat file to setup the paths needed.



  • Ok perfect, I finally made it, but I don't understand where I have to put the dll to run a project with MySQL ?



  • @Detordreur like all sql plugin -> /sqldrivers



  • This is what i've done, in the folder of the executable, but when I try to compile this gives me :
    (10061) QMYSQL : Unable to connect


  • Lifetime Qt Champion

    Isn't it rather when you run your application ?

    If it can't connect, did you check your network settings ? Is your database running ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.