Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cant connect to mysql database: QMYSQL driver not loaded
Forum Updated to NodeBB v4.3 + New Features

Cant connect to mysql database: QMYSQL driver not loaded

Scheduled Pinned Locked Moved Solved General and Desktop
46 Posts 12 Posters 50.1k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cdwijs
    wrote on 16 Jul 2018, 22:23 last edited by
    #21

    I have done the steps again:
    c:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1"\lib
    and
    mingw32-make

    After this, there's no mysql.dll below C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers (in fact, there's no mysql.dll on my entire C:\ drive)

    However, this directory is newly created:
    C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers
    it contains the following files: (and a few extra files with sqlite in the name)
    qsqlmysql.dll
    qsqlmysqld.dll
    qsqlodbc.dll
    qsqlodbcd.dll

    Where do I put these?

    Cheers,
    Cedric

    J L 2 Replies Last reply 17 Jul 2018, 05:41
    0
    • C cdwijs
      16 Jul 2018, 22:23

      I have done the steps again:
      c:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1"\lib
      and
      mingw32-make

      After this, there's no mysql.dll below C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers (in fact, there's no mysql.dll on my entire C:\ drive)

      However, this directory is newly created:
      C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers
      it contains the following files: (and a few extra files with sqlite in the name)
      qsqlmysql.dll
      qsqlmysqld.dll
      qsqlodbc.dll
      qsqlodbcd.dll

      Where do I put these?

      Cheers,
      Cedric

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 17 Jul 2018, 05:41 last edited by
      #22

      @cdwijs You forgot

      mingw32-make install
      

      as shown in the documentation...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • C Offline
        C Offline
        cdwijs
        wrote on 17 Jul 2018, 07:26 last edited by
        #23

        Thanks jsulm,

        I've just done the mingw32-make install, but my Qt program does not load the driver yet.
        I've installed Process monitor (https://docs.microsoft.com/en-us/sysinternals/downloads/procmon) to monitor the syscalls from my application. I've done the following steps with it:
        1-run procmon.exe
        2-choose filter-reset filter
        3-run my program
        4-choose tools-process tree
        5-select my program, right click, and choose "Add process to include filter" Now only the syscalls from my program are shown.
        6)ctrl-f mysql and press F3 a couple of times. Now I see BUFFER OVERFLOW. Can this be a problem?

        CreateFile C:\Qt\5.10.1\mingw53_32\plugins\sqldrivers\qsqlmysql.dll SUCCESS Desired Access: Generic Read, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: n/a, OpenResult: Opened
        QueryInformationVolume C:\Qt\5.10.1\mingw53_32\plugins\sqldrivers\qsqlmysql.dll BUFFER OVERFLOW VolumeCreationTime: 31-01-2018 09:56:48, VolumeSerialNumber: AC0C-32AB, SupportsObjects: True, VolumeLabel: WinÀ
        

        Also, I see my program searches for libmysql.dll in the following paths:

        C:\ProgramData\Oracle\Java\javapath_target_378770\LIBMYSQL.DLL
        C:\Windows\SysWOW64\libmysql.dll
        C:\Windows\libmysql.dll
        C:\Windows\SysWOW64\wbem\libmysql.dll
        C:\Windows\SysWOW64\WindowsPowerShell\v1.0\libmysql.dll
        C:\Program Files\Git\cmd\libmysql.dll
        C:\Program Files\TortoiseGit\bin\libmysql.dll
        C:\Qt\Tools\mingw530_32\bin\libmysql.dll
        C:\Program Files\PuTTY\libmysql.dll
        C:\Program Files\MySQL\MySQL Utilities 1.6\libmysql.dll
        C:\Qt\5.10.1\mingw53_32\bin\libmysql.dll
        

        Mysql.dll is present on my system: C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib, so I copy it into
        C:\Qt\Tools\mingw530_32\bin
        Now I see libmysql.dll being successfully loaded by my program, and the error message is gone, and after supplying the correct password, I now have a connection into my mysql database.

        Thank you all for your assistance.

        Shall I edit my opening post with the solution, place it below, or make a new post about it?

        Cheers,
        Cedric

        J 1 Reply Last reply 17 Jul 2018, 07:31
        0
        • C cdwijs
          17 Jul 2018, 07:26

          Thanks jsulm,

          I've just done the mingw32-make install, but my Qt program does not load the driver yet.
          I've installed Process monitor (https://docs.microsoft.com/en-us/sysinternals/downloads/procmon) to monitor the syscalls from my application. I've done the following steps with it:
          1-run procmon.exe
          2-choose filter-reset filter
          3-run my program
          4-choose tools-process tree
          5-select my program, right click, and choose "Add process to include filter" Now only the syscalls from my program are shown.
          6)ctrl-f mysql and press F3 a couple of times. Now I see BUFFER OVERFLOW. Can this be a problem?

          CreateFile C:\Qt\5.10.1\mingw53_32\plugins\sqldrivers\qsqlmysql.dll SUCCESS Desired Access: Generic Read, Disposition: Open, Options: Synchronous IO Non-Alert, Non-Directory File, Attributes: N, ShareMode: Read, Write, AllocationSize: n/a, OpenResult: Opened
          QueryInformationVolume C:\Qt\5.10.1\mingw53_32\plugins\sqldrivers\qsqlmysql.dll BUFFER OVERFLOW VolumeCreationTime: 31-01-2018 09:56:48, VolumeSerialNumber: AC0C-32AB, SupportsObjects: True, VolumeLabel: WinÀ
          

          Also, I see my program searches for libmysql.dll in the following paths:

          C:\ProgramData\Oracle\Java\javapath_target_378770\LIBMYSQL.DLL
          C:\Windows\SysWOW64\libmysql.dll
          C:\Windows\libmysql.dll
          C:\Windows\SysWOW64\wbem\libmysql.dll
          C:\Windows\SysWOW64\WindowsPowerShell\v1.0\libmysql.dll
          C:\Program Files\Git\cmd\libmysql.dll
          C:\Program Files\TortoiseGit\bin\libmysql.dll
          C:\Qt\Tools\mingw530_32\bin\libmysql.dll
          C:\Program Files\PuTTY\libmysql.dll
          C:\Program Files\MySQL\MySQL Utilities 1.6\libmysql.dll
          C:\Qt\5.10.1\mingw53_32\bin\libmysql.dll
          

          Mysql.dll is present on my system: C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib, so I copy it into
          C:\Qt\Tools\mingw530_32\bin
          Now I see libmysql.dll being successfully loaded by my program, and the error message is gone, and after supplying the correct password, I now have a connection into my mysql database.

          Thank you all for your assistance.

          Shall I edit my opening post with the solution, place it below, or make a new post about it?

          Cheers,
          Cedric

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 17 Jul 2018, 07:31 last edited by
          #24

          @cdwijs The solution is already at the end of this thread, just mark it as solved.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • C cdwijs
            16 Jul 2018, 22:23

            I have done the steps again:
            c:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1"\lib
            and
            mingw32-make

            After this, there's no mysql.dll below C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers (in fact, there's no mysql.dll on my entire C:\ drive)

            However, this directory is newly created:
            C:\Qt\5.11.1\Src\qtbase\src\plugins\sqldrivers\plugins\sqldrivers
            it contains the following files: (and a few extra files with sqlite in the name)
            qsqlmysql.dll
            qsqlmysqld.dll
            qsqlodbc.dll
            qsqlodbcd.dll

            Where do I put these?

            Cheers,
            Cedric

            L Offline
            L Offline
            lucaynnofrota
            wrote on 11 Nov 2018, 02:51 last edited by
            #25

            @cdwijs
            I'm having trouble to execute these code lines

            My cmd input:

            D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
            qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"

            mingw32-make sub-mysql

            My cmd output:

            C:\Users\lucya\Desktop>D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
            'D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers' is not recognized as an internal or external command,
            operable program or batch file.

            C:\Users\lucya\Desktop>qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"
            Usage: qmake [mode] [options] [files]

            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 built,
            defaults to *; *; *; *.ts; *.xlf; *.qrc
            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]

            C:\Users\lucya\Desktop>mingw32-make sub-mysql
            mingw32-make: *** No rule to make target 'sub-mysql'. Stop.

            J 1 Reply Last reply 12 Nov 2018, 06:22
            0
            • L lucaynnofrota
              11 Nov 2018, 02:51

              @cdwijs
              I'm having trouble to execute these code lines

              My cmd input:

              D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
              qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"

              mingw32-make sub-mysql

              My cmd output:

              C:\Users\lucya\Desktop>D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
              'D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers' is not recognized as an internal or external command,
              operable program or batch file.

              C:\Users\lucya\Desktop>qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"
              Usage: qmake [mode] [options] [files]

              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 built,
              defaults to *; *; *; *.ts; *.xlf; *.qrc
              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]

              C:\Users\lucya\Desktop>mingw32-make sub-mysql
              mingw32-make: *** No rule to make target 'sub-mysql'. Stop.

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 12 Nov 2018, 06:22 last edited by
              #26

              @lucaynnofrota said in Cant connect to mysql database: QMYSQL driver not loaded:

              D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers

              This is not a command but a directory!
              Please change to

              cd D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
              

              then

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

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              L 1 Reply Last reply 12 Nov 2018, 08:56
              1
              • J jsulm
                12 Nov 2018, 06:22

                @lucaynnofrota said in Cant connect to mysql database: QMYSQL driver not loaded:

                D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers

                This is not a command but a directory!
                Please change to

                cd D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
                

                then

                qmake -- MYSQL_INCDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" MYSQL_LIBDIR="C:\Program Files\MySQL\MySQL Server 8.0\lib"
                
                L Offline
                L Offline
                lucaynnofrota
                wrote on 12 Nov 2018, 08:56 last edited by
                #27

                @jsulm

                Thanks for reply but I made a mistake. I removed CD on publication. But I have executed the correct code.

                J 1 Reply Last reply 12 Nov 2018, 09:01
                0
                • L lucaynnofrota
                  12 Nov 2018, 08:56

                  @jsulm

                  Thanks for reply but I made a mistake. I removed CD on publication. But I have executed the correct code.

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 12 Nov 2018, 09:01 last edited by
                  #28

                  @lucaynnofrota If you get
                  "'D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers' is not recognized as an internal or external command,
                  operable program or batch file."
                  it means that you're trying to execute it. So, are you really sure you did

                  cd D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
                  

                  ?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  L 1 Reply Last reply 12 Nov 2018, 10:14
                  0
                  • J jsulm
                    12 Nov 2018, 09:01

                    @lucaynnofrota If you get
                    "'D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers' is not recognized as an internal or external command,
                    operable program or batch file."
                    it means that you're trying to execute it. So, are you really sure you did

                    cd D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers
                    

                    ?

                    L Offline
                    L Offline
                    lucaynnofrota
                    wrote on 12 Nov 2018, 10:14 last edited by
                    #29

                    @jsulm
                    Yeah.

                    0_1542017602132_ebe34f6b-8996-4fca-ac11-4ede9bca52e1-image.png

                    I'm using this code in .bat file!

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      realmodus
                      wrote on 21 Mar 2019, 20:00 last edited by
                      #30

                      Does anyone succeed with MySQL and Qt under Windows? I believe that nobody reaches the DB. So! no MySQL connection with Qt? Those who give their help didn't really try, I wonder.

                      JonBJ 1 Reply Last reply 21 Mar 2019, 21:19
                      0
                      • R realmodus
                        21 Mar 2019, 20:00

                        Does anyone succeed with MySQL and Qt under Windows? I believe that nobody reaches the DB. So! no MySQL connection with Qt? Those who give their help didn't really try, I wonder.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on 21 Mar 2019, 21:19 last edited by
                        #31

                        @realmodus
                        No idea what you're talking about.

                        @jsulm
                        Your

                        cd D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers

                        I suspect this didn't work for OP as it needs to be cd /d D:\... to make the D: drive the current drive for the subsequent qmake command to be on the right drive, else it'll still be on C:?

                        J 1 Reply Last reply 22 Mar 2019, 06:34
                        3
                        • JonBJ JonB
                          21 Mar 2019, 21:19

                          @realmodus
                          No idea what you're talking about.

                          @jsulm
                          Your

                          cd D:\Qt\5.11.2\Src\qtbase\src\plugins\sqldrivers

                          I suspect this didn't work for OP as it needs to be cd /d D:\... to make the D: drive the current drive for the subsequent qmake command to be on the right drive, else it'll still be on C:?

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 22 Mar 2019, 06:34 last edited by
                          #32

                          @JonB You're right I didn't think about the drive

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          1
                          • F Offline
                            F Offline
                            fyang
                            wrote on 5 Jun 2019, 13:44 last edited by
                            #33

                            we had the same driver nod loaded issue. we fixed by switch compiler as 32bit from originally 64bit to compile application in Qt. Hope this help. some of our machine is 32bit machine.

                            1 Reply Last reply
                            0
                            • C cdwijs
                              16 Jul 2018, 14:39

                              Hi All,

                              I'm one step closer to my goal, I can now build the plugin. I cannot yet connect to my database.
                              Steps I've taken:

                              1. Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi
                              2. Add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path
                              3. Open cmd.exe, and enter the following commands:
                              c:\Qt\5.10.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1"\lib
                              
                              Running configuration tests...
                              Checking for DB2 (IBM)... no
                              Checking for InterBase... no
                              Checking for MySQL... yes
                              Checking for OCI (Oracle)... no
                              Checking for ODBC... yes
                              Checking for PostgreSQL... no
                              Checking for SQLite (version 2)... no
                              Checking for TDS (Sybase)... no
                              Done running configuration tests.
                              
                              Configure summary:
                              
                              Qt Sql:
                                DB2 (IBM) .............................. no
                                InterBase .............................. no
                                MySql .................................. yes
                                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, Qt is installed.
                              You should NOT run 'mingw32-make install'.
                              Note that this build cannot be deployed to other machines or devices.
                              
                              Prior to reconfiguration, make sure you remove any leftovers from
                              the previous build.
                              
                              mingw32-make
                              
                              <<lots of text>>
                              
                              1. Create a new Qt program, with the following options:
                                Qt widgets application
                                Name: sqlTest
                                Kit: Desktop Qt 5.11.1 MinGB 32 bit (default)
                                ClassName: (MainWindow) (default)
                                Version control: Git

                              mysql.pro

                              QT       += core gui sql
                              greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                              TARGET = sqlTest
                              TEMPLATE = app
                              DEFINES += QT_DEPRECATED_WARNINGS
                              SOURCES += \
                                      main.cpp \
                                      mainwindow.cpp
                              HEADERS += \
                                      mainwindow.h
                              FORMS += \
                                      mainwindow.ui
                              

                              mainwindow.cpp

                              #include "mainwindow.h"
                              #include "ui_mainwindow.h"
                              #include <QtSql>
                              #include <QDebug>
                              MainWindow::MainWindow(QWidget *parent) :
                                  QMainWindow(parent),
                                  ui(new Ui::MainWindow)
                              {
                                  ui->setupUi(this);
                              
                                  QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
                                 db.setHostName("localhost");
                                 db.setDatabaseName("world");
                                 db.setUserName("root");
                                 db.setPassword("PassOlyForForumQuestion");
                                 bool ok = db.open();
                                 qDebug()<<ok;
                              }
                              
                              MainWindow::~MainWindow()
                              {
                                  delete ui;
                              }
                              

                              Program output:

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

                              Cheers,
                              Cedric

                              H Offline
                              H Offline
                              Heman
                              wrote on 3 Aug 2019, 23:23 last edited by
                              #34

                              @cdwijs I wish to information you that I have been following the steps you took to build QMySQL driver for Qt 5.13.0 though. However, I got lost at the point you gave three (3) steps you took to get qmake identify mysql driver because at that point my qmake could not identify the driver:

                              1. Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi

                              2. Add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path

                              3. Open cmd.exe, and enter the following commands:

                              4. Are there some other things you did which, perhaps, you did not mention on the steps?

                              5. In step 2 of your procedure, you said you added C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path. Did you mean path of system variable?

                              I installed MySQL 8.016 community edition and used the same c++ connector, 6.1 32-bit you used.

                              Followings are the commands I used but qmake could detect MySQL source driver:
                              cd C:\Qt\Qt5.13.0\5.13.0\Src\qtbase\src\plugins\sqldrivers
                              qmake -- MYSQL_INCDIR=C:\Program~Files~(x86)\MySQL\MySQL~Connector~C~6.1\include "MYSQL_LIBDIR=C:\Program~Files~(x86)\MySQL\MySQL~Connector~C~6.1\lib\opt"

                              Can you help where I got it wrong?

                              Cheers,

                              Heman.

                              J 1 Reply Last reply 5 Aug 2019, 04:16
                              0
                              • H Heman
                                3 Aug 2019, 23:23

                                @cdwijs I wish to information you that I have been following the steps you took to build QMySQL driver for Qt 5.13.0 though. However, I got lost at the point you gave three (3) steps you took to get qmake identify mysql driver because at that point my qmake could not identify the driver:

                                1. Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi

                                2. Add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path

                                3. Open cmd.exe, and enter the following commands:

                                4. Are there some other things you did which, perhaps, you did not mention on the steps?

                                5. In step 2 of your procedure, you said you added C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path. Did you mean path of system variable?

                                I installed MySQL 8.016 community edition and used the same c++ connector, 6.1 32-bit you used.

                                Followings are the commands I used but qmake could detect MySQL source driver:
                                cd C:\Qt\Qt5.13.0\5.13.0\Src\qtbase\src\plugins\sqldrivers
                                qmake -- MYSQL_INCDIR=C:\Program~Files~(x86)\MySQL\MySQL~Connector~C~6.1\include "MYSQL_LIBDIR=C:\Program~Files~(x86)\MySQL\MySQL~Connector~C~6.1\lib\opt"

                                Can you help where I got it wrong?

                                Cheers,

                                Heman.

                                J Offline
                                J Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on 5 Aug 2019, 04:16 last edited by
                                #35

                                @heman said in Cant connect to mysql database: QMYSQL driver not loaded:

                                Are there some other things you did which, perhaps, you did not mention on the steps?

                                "mingww32-make install" after successful build is missing.

                                You should not set your PATH globally, do it in the cmd.exe window where you build.
                                These paths looks strange:
                                "C:\Program~Files~(x86)\MySQL\MySQL~Connector~C~6.1\include "MYSQL_LIBDIR=C:\Program~Files~(x86)\MySQL\MySQL~Connector~C~6.1\lib\opt""
                                Use complete paths with escaped spaces. Even better would be to install MySQL stuff in a directory without spaces.

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                2
                                • H Offline
                                  H Offline
                                  Heman
                                  wrote on 12 Aug 2019, 00:19 last edited by
                                  #36

                                  I get it now. It works.
                                  I might have included some kind of atrocities who knows? However, these are the steps I took:

                                  1. I installed MySQL community edition
                                  2. I installed mysql connector c 6.1
                                  3. I created a .bat file with the following commands: C:\Windows\System32\cmd.exe /E:ON /V:ON /K C:\Qt\Qt5.13.0\5.13.0\mingw73_32\bin\qmake.exe
                                    SET _ROOT=C:\Qt\Qt5.13.0
                                    SET PATH=C:\Qt\Qt5.13.0\5.13.0\mingw73_32\bin;C:\Qt\Qt5.13.0\Tools\mingw730_32\bin;%PATH%
                                  4. I run cd C:\Qt\Qt5.13.0\5.13.0\Src\qtbase\src\plugins\sqldrivers
                                  5. I run qmake -- MYSQL_INCDIR="C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib"
                                    mingw32-make
                                    ming32-make install
                                  6. And lastly, I copied libmysql.dll from C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib to C:\Qt\Qt5.13.0\Tools\mingw730_32\bin
                                  1 Reply Last reply
                                  0
                                  • C cdwijs
                                    16 Jul 2018, 14:39

                                    Hi All,

                                    I'm one step closer to my goal, I can now build the plugin. I cannot yet connect to my database.
                                    Steps I've taken:

                                    1. Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi
                                    2. Add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path
                                    3. Open cmd.exe, and enter the following commands:
                                    c:\Qt\5.10.1\Src\qtbase\src\plugins\sqldrivers>qmake -- MYSQL_INCDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" MYSQL_LIBDIR="c:\Program Files (x86)\MySQL\MySQL Connector C 6.1"\lib
                                    
                                    Running configuration tests...
                                    Checking for DB2 (IBM)... no
                                    Checking for InterBase... no
                                    Checking for MySQL... yes
                                    Checking for OCI (Oracle)... no
                                    Checking for ODBC... yes
                                    Checking for PostgreSQL... no
                                    Checking for SQLite (version 2)... no
                                    Checking for TDS (Sybase)... no
                                    Done running configuration tests.
                                    
                                    Configure summary:
                                    
                                    Qt Sql:
                                      DB2 (IBM) .............................. no
                                      InterBase .............................. no
                                      MySql .................................. yes
                                      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, Qt is installed.
                                    You should NOT run 'mingw32-make install'.
                                    Note that this build cannot be deployed to other machines or devices.
                                    
                                    Prior to reconfiguration, make sure you remove any leftovers from
                                    the previous build.
                                    
                                    mingw32-make
                                    
                                    <<lots of text>>
                                    
                                    1. Create a new Qt program, with the following options:
                                      Qt widgets application
                                      Name: sqlTest
                                      Kit: Desktop Qt 5.11.1 MinGB 32 bit (default)
                                      ClassName: (MainWindow) (default)
                                      Version control: Git

                                    mysql.pro

                                    QT       += core gui sql
                                    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                                    TARGET = sqlTest
                                    TEMPLATE = app
                                    DEFINES += QT_DEPRECATED_WARNINGS
                                    SOURCES += \
                                            main.cpp \
                                            mainwindow.cpp
                                    HEADERS += \
                                            mainwindow.h
                                    FORMS += \
                                            mainwindow.ui
                                    

                                    mainwindow.cpp

                                    #include "mainwindow.h"
                                    #include "ui_mainwindow.h"
                                    #include <QtSql>
                                    #include <QDebug>
                                    MainWindow::MainWindow(QWidget *parent) :
                                        QMainWindow(parent),
                                        ui(new Ui::MainWindow)
                                    {
                                        ui->setupUi(this);
                                    
                                        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
                                       db.setHostName("localhost");
                                       db.setDatabaseName("world");
                                       db.setUserName("root");
                                       db.setPassword("PassOlyForForumQuestion");
                                       bool ok = db.open();
                                       qDebug()<<ok;
                                    }
                                    
                                    MainWindow::~MainWindow()
                                    {
                                        delete ui;
                                    }
                                    

                                    Program output:

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

                                    Cheers,
                                    Cedric

                                    H Offline
                                    H Offline
                                    hobbyProgrammer
                                    wrote on 29 Nov 2019, 10:49 last edited by
                                    #37

                                    @cdwijs said in Cant connect to mysql database: QMYSQL driver not loaded:

                                    Hi All,

                                    I'm one step closer to my goal, I can now build the plugin. I cannot yet connect to my database.
                                    Steps I've taken:

                                    1. Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi
                                    2. Add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path

                                    Hi,
                                    I am struggling with the same issue, where exactly did you add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to?

                                    C 1 Reply Last reply 29 Nov 2019, 10:57
                                    0
                                    • H hobbyProgrammer
                                      29 Nov 2019, 10:49

                                      @cdwijs said in Cant connect to mysql database: QMYSQL driver not loaded:

                                      Hi All,

                                      I'm one step closer to my goal, I can now build the plugin. I cannot yet connect to my database.
                                      Steps I've taken:

                                      1. Download and install https://downloads.mysql.com/archives/get/file/mysql-connector-c-6.1.11-win32.msi
                                      2. Add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to the path

                                      Hi,
                                      I am struggling with the same issue, where exactly did you add C:\Qt\Tools\mingw530_32\bin and C:\Qt\5.10.1\mingw53_32\bin to?

                                      C Offline
                                      C Offline
                                      cdwijs
                                      wrote on 29 Nov 2019, 10:57 last edited by
                                      #38

                                      @hobbyProgrammer I've added them to the PATH. On widows7, you can find that setting here:
                                      start->control panel->system and security->system->Advanced system settings->Advanced->Environment Variables->System variables->Path->Edit...

                                      You can see the current value of the path variable by start->run->cmd and the command:
                                      echo %PATH%

                                      H 1 Reply Last reply 29 Nov 2019, 11:07
                                      0
                                      • C cdwijs
                                        29 Nov 2019, 10:57

                                        @hobbyProgrammer I've added them to the PATH. On widows7, you can find that setting here:
                                        start->control panel->system and security->system->Advanced system settings->Advanced->Environment Variables->System variables->Path->Edit...

                                        You can see the current value of the path variable by start->run->cmd and the command:
                                        echo %PATH%

                                        H Offline
                                        H Offline
                                        hobbyProgrammer
                                        wrote on 29 Nov 2019, 11:07 last edited by
                                        #39

                                        @cdwijs thanks, but unfortunately it didn't work for me :(

                                        J 1 Reply Last reply 29 Nov 2019, 11:27
                                        0
                                        • H hobbyProgrammer
                                          29 Nov 2019, 11:07

                                          @cdwijs thanks, but unfortunately it didn't work for me :(

                                          J Offline
                                          J Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on 29 Nov 2019, 11:27 last edited by
                                          #40

                                          @hobbyProgrammer Did you log out and log in after changing PATH?

                                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          H 1 Reply Last reply 29 Nov 2019, 11:27
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved