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

MYSQL error in Qt



  • 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

    1. 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.


  • @tmapp Hi, thanks for the help. I'm new to qt, and I'm not sure what you meant (what you want me to do exactly) by the first bullet point, could you explain please. sorry for the inconvenience.



  • @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
    75b76ebb-8e73-4ea2-8651-aa387c415142-grafik.png

    40c65099-609f-4ad5-9d42-aa343eaf795b-grafik.png



  • @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.


  • Lifetime Qt Champion

    @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


  • Lifetime Qt Champion

    @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


  • Lifetime Qt Champion

    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?


  • Lifetime Qt Champion

    @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.


  • Lifetime Qt Champion

    @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.


  • Lifetime Qt Champion

    @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


  • Lifetime Qt Champion

    @Alfie-Anil Yes, absolute path like c:\Qt\5.12.0\mingw73_64\bin\qmake.exe



  • Yes That's what I did



  • @jsulm Actually I did get it working. But then I ran into the problem that although the problem was gone, none of the sql commands would not work so I was trying to fix that. Then, I ran into a problem with the computer which meant I had to reset the computer. So now I have to do it all over again (hahaha). (I've tried all the steps I did before)


Log in to reply