MYSQL error in Qt
-
Hi everyone,
I'm using MySql in my code, and I get this problem:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
I have tried adding the .lib files to the mingw etc and then cleaning and rebuilding the project but that doesn't solve the issue.
Any help is greatly appreciated.
Thanks -
@Alfie-Anil
This has been asked 100 times here and on the web. You could search this forum, we just dealt with it again the other day: https://forum.qt.io/topic/119267/qmysql-qpsql-qpsql7-driver-not-found/2. It doesn't matter which driver you are trying, the first action to do is as per my post at that link. -
there are 2 cases :
1. the driver does not exists in plugin/sqldrivers
2. an other error coming from you project.
Solutions:
1. you need to make the driver by your self, as mentioned in the topic: here
2. active the QT_DEBUG_PLUGINS and past the errors here, that way you can help other's understand the issue to help you, as @JonB said.
Good luck. -
Hi ,
I tested the following solution and worked for me
Here is your solution :- start by commenting QMAKE_USE += mysql by a #
in PATH_TO_QT_Src\qtbase\src\plugins\sqldrivers\mysql\mysql.pro
AND : follow this instructions link here
- don't forget to copy libmysql.dll to mingw32 bin path and to your project path
Congrats!
- Just remember: if you want 32bit use the 32bit versions , but 64 use the 64 even mingw use 64 .... respect the version to have full working driver.
- other remark: don't use path's where spaces exists exmpl : C:\Program Files\Mysql....
this will create error in mingw-make ( Files not recognized ..... ) but use strict path's like : C:\Mysql...... etc
Good Luck.
- start by commenting QMAKE_USE += mysql by a #
-
@Alfie-Anil you can use my precompiled QMYSQL driver if you like. Get it from https://github.com/thecodemonkey86/qt_mysql_driver/releases according to your Qt version and compiler and put qsqlmysql.dll (if release build) or qsqlmysqld.dll (if debug build) in your application subdirectory "sqldrivers", plus in application directory (or somewhere else referenced by your PATH variable) libmysql.dll (plus, if required, the DLLs from OpenSSL - libssl-1_1-x64.dll and libcrypto-1_1-x64.dll)
Edit: added screen shot how it looks like in Windows Explorer
-
@Alfie-Anil edit the file : PATH_TO_QT_Src\qtbase\src\plugins\sqldrivers\mysql\mysql.pro in a text editor you prefer, you'll find a line QMAKE_USE +=mysql
add before it # , it'll be like this : #QMAKE_USE += mysql
save the file and procced with the next steps. -
@tmapp There is no reason to modify any qt source or config file when you want to compile a sql plugin...
-
@Christian-Ehrlicher that's how it worked with me on postgresql and mysql ; otherwise it'll display an error : mysql model is not defined , and same for postgresql ( speaking about QT 5.11 )
-
@tmapp Hi, I've tried that but nothing seems to be working. I'm still getting the same error
-
@Alfie-Anil said in MYSQL error in Qt:
Hi, I've tried that but nothing seems to be working. I'm still getting the same error
Not very helpful answer...
Please start with a clean qt source tree, follow the documentation and post the output. Also notice the comments to config.log in the documentation
-
Hello everyone, I was following through the documentation as suggested by @Christian-Ehrlicher . The first command I added was 'qmake -- MYSQL_INCDIR="C:/Program Files/MySQL/MySQL Connector C 6.1/include" MYSQL_LIBDIR="C:/Program Files/MySQL/MySQL Connector C 6.1/lib"
But the outcome was different to that which was in the documentation. This was what I got:
QMake has two modes, one mode for generating project files based on some heuristics, and the other for generating makefiles. Normally you shouldn't need to specify a mode, as makefile generation is the default mode for qmake, but you may use this to test qmake on an existing project Mode: -project Put qmake into project file generation mode In this mode qmake interprets [files] as files to be added to the .pro file. By default, all files with known source extensions are added. Note: The created .pro file probably will need to be edited. For example add the QT variable to specify what modules are required. -makefile Put qmake into makefile generation mode (default) In this mode qmake interprets files as project files to be processed, if skipped qmake will try to find a project file in your current working directory Warnings Options: -Wnone Turn off all warnings; specific ones may be re-enabled by later -W options -Wall Turn on all warnings -Wparser Turn on parser warnings -Wlogic Turn on logic warnings (on by default) -Wdeprecated Turn on deprecation warnings (on by default) Options: * You can place any variable assignment in options and it will be * * processed as if it was in [files]. These assignments will be * * processed before [files] by default. * -o file Write output to file -d Increase debug level -t templ Overrides TEMPLATE as templ -tp prefix Overrides TEMPLATE so that prefix is prefixed into the value -help This help -v Version information -early All subsequent variable assignments will be parsed right before default_pre.prf -before All subsequent variable assignments will be parsed right before [files] (the default) -after All subsequent variable assignments will be parsed after [files] -late All subsequent variable assignments will be parsed right after default_post.prf -norecursive Don't do a recursive search -recursive Do a recursive search -set <prop> <value> Set persistent property -unset <prop> Unset persistent property -query <prop> Query persistent property. Show all if <prop> is empty. -qtconf file Use file instead of looking for qt.conf -cache file Use file as cache [makefile mode only] -spec spec Use spec as QMAKESPEC [makefile mode only] -nocache Don't use a cache file [makefile mode only] -nodepend Don't generate dependencies [makefile mode only] -nomoc Don't generate moc targets [makefile mode only] -nopwd Don't look for files in pwd [project mode only]
Any ideas?
Thanks -
Hi,
You are likely not in the right folder, likely in your Qt installation rather than sources.
-
So I opened the terminal from the qt5.13.2 mingw32. Is that where i open the terminal from or is it another directory?
-
@Alfie-Anil said in MYSQL error in Qt:
Is that where i open the terminal from or is it another directory?
That's correct. But then you have to go to the correct source dir as you can see in the documentation: <srcdir>\qtbase\src\plugins\sqldrivers
Is it really that hard to follow the instructions? -
I've tried everything said but still comes up with the exact error.
-
@Alfie-Anil said in MYSQL error in Qt:
I've tried everything said but still comes up with the exact error.
Did you really call the correct qmake in the correct directory? I would guess no.
-
@Christian-Ehrlicher Yes I did. As stated in the documentation I cd to the correct directory and then followed the commands as given.
-
@Alfie-Anil The question was rather: did you call correct qmake?
To make sure you call correct qmake use absolute path (instead of simply calling qmake). -
So do you mean 'C:<NecessaryDirectory>? Yes