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. QSqlDatabase: QMYSQL driver not loaded
Forum Updated to NodeBB v4.3 + New Features

QSqlDatabase: QMYSQL driver not loaded

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 5 Posters 1.4k Views 2 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.
  • T ThiagoSys

    Hello, my english is not the best but i will try.

    Im developing an application in python and Qt Designer with PyQt6. I want to use QSqlDatabase and QSqlTableView. My first problem when connecting QSqlDatabase to mysql was the connection failure due to the lack of the plugin for mysql, where te message "QSqlDatabase: available drivers: QSQLITE QMIMER QODBC QPSQL" was returned. Searching the forums for a solution, I found several tutorials on how to compile the plugin, but most of my attempts failed, I believe because I installed Qt version 6.8.1 to carry out the compilation, which from what some people returned was not working well.

    Until I found the video linked below https://youtu.be/5NypUQ5AtgU and decided to install version 6.7.3 to try to compile, which gave a positive result carrying out the compilation as shown in the video. After compiling, i copy the mysql archives from "C:\Qt\6.7.3\mingw_64\plugins\sqldrivers" to "C:\Users\thiag\AppData\Local\Programs\Python\Python313\Lib\site-packages\PyQt6\Qt6\plugins\sqldrivers" which is my python installation directory. I saw this last step in some of the posts and in a way it worked, since the return message is now "QSqlDatabase: available drivers: QSQLITE QMIMER QMARIADB QMYSQL QODBC QPSQL" but the connection still does not occur. Remembering that I am using python in visual studio code and PyQt6. I would like to know what else I need to do to make everything work well, or if I did something wrong in the process. Below I leave the code for the connection part and thank you in advance for your help.

    self.dbQSql = QSqlDatabase.addDatabase("QMYSQL")  # Driver for MySQL
    self.dbQSql.setHostName(dbMysql.host)
    self.dbQSql.setUserName(dbMysql.user)
    self.dbQSql.setPassword(dbMysql.password)
    self.dbQSql.setDatabaseName(dbMysql.database)
    
    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #2

    @ThiagoSys
    Because you now have QMYSQL as a listed driver you have done that part correctly.

    Now set environment variable QT_DEBUG_PLUGINS=1 and then run your code. You will get lots of diagnostic output. Look through it for QMYSQL, particularly at the end of the output, it should tell you why it cannot be loaded (usually missing dependencies).

    On a separate matter: although it is not the cause of your current issue, nonetheless as per the docs you ought not store a reference to a SQL database in a self class variable (self.dbQSql = QSqlDatabase.addDatabase("QMYSQL")). You should rather store that in a local variable, and use QSqlDatabase.database() when you want to access it again later on.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      ThiagoSys
      wrote on last edited by ThiagoSys
      #3

      Should I run the command "export QT_DEBUG_PLUGINS=1" with the terminal in which directory? Forgot to mention but I'm on Windows

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Hi,

        If you are running from the command line, yes.
        Otherwise, you can do that in your Python script with os module before doing anything Qt. Or if you are using an IDE, it should provide a mean to change the environment variables.

        From experience, you will likely have a message stating that the dependencies of the MySQL plugin cannot be found.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • T Offline
          T Offline
          ThiagoSys
          wrote on last edited by
          #5

          I managed to activate the more detailed messages and the result was

          qt.core.plugin.factoryloader: Got keys from plugin meta data QList("QPSQL")
          qt.core.plugin.factoryloader: checking directory path "C:/Users/thiag/AppData/Local/Programs/Python/Python313/sqldrivers" ...
          qt.core.library: "C:/Users/thiag/AppData/Local/Programs/Python/Python313/Lib/site-packages/PyQt6/Qt6/plugins/sqldrivers/qsqlmysql.dll" cannot load: Cannot load library C:\Users\thiag\AppData\Local\Programs\Python\Python313\Lib\site-packages\PyQt6\Qt6\plugins\sqldrivers\qsqlmysql.dll: Não foi possível encontrar o procedimento especificado.
          qt.core.plugin.loader: QLibraryPrivate::loadPlugin failed on "C:/Users/thiag/AppData/Local/Programs/Python/Python313/Lib/site-packages/PyQt6/Qt6/plugins/sqldrivers/qsqlmysql.dll" : "Cannot load library C:\Users\thiag\AppData\Local\Programs\Python\Python313\Lib\site-packages\PyQt6\Qt6\plugins\sqldrivers\qsqlmysql.dll: Não foi possível encontrar o procedimento especificado."

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            I did not realize...
            You might be mixing and matching Qt versions and compilers which is a no go.
            Did you check which version of Qt is PyQt6 using ?
            Did you verify that you are using the same compiler to build the plug-in that was used for PyQt6 ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • T Offline
              T Offline
              ThiagoSys
              wrote on last edited by
              #7

              In the video that I used as a base, the mingw compiler was used, I believe that this is not the one used by Qt. How can I check the version that PyQt6 is using and which compiler it is?

              1 Reply Last reply
              0
              • T Offline
                T Offline
                ThiagoSys
                wrote on last edited by ThiagoSys
                #8

                Hello again.

                I managed to compile the plugin correctly using msvc using version 6.7.3 but it returned the error

                Cannot mix incompatible Qt library (6.7.3) with this library (6.8.1)
                

                So I tried to do the same process in version 6.8.1, but when running the command

                call C:\Qt\6.8.1\msvc2022_64\bin\qt-cmake.bat -G "Ninja" . -DMySQL_INLCUDEDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" -DMySQL_LIBRARY="C:\Program Files\MySQL\MySQL Server 8.0\lib\libmysql.lib" -DCMAKE_INSTALL_PREFIX="C:\Qt\6.8 .1\msvc2022_64"
                

                I get the error

                -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
                -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
                -- Looking for pthread_create in pthreads
                -- Looking for pthread_create in pthreads - not found
                -- Looking for pthread_create in pthread
                -- Looking for pthread_create in pthread - not found
                

                Is this a problem with version? I used the same method that had worked in version 6.7.3. If it's a version issue, will I have to wait for a new version to be released by PyQt6?

                Christian EhrlicherC 1 Reply Last reply
                0
                • T ThiagoSys

                  Hello again.

                  I managed to compile the plugin correctly using msvc using version 6.7.3 but it returned the error

                  Cannot mix incompatible Qt library (6.7.3) with this library (6.8.1)
                  

                  So I tried to do the same process in version 6.8.1, but when running the command

                  call C:\Qt\6.8.1\msvc2022_64\bin\qt-cmake.bat -G "Ninja" . -DMySQL_INLCUDEDIR="C:\Program Files\MySQL\MySQL Server 8.0\include" -DMySQL_LIBRARY="C:\Program Files\MySQL\MySQL Server 8.0\lib\libmysql.lib" -DCMAKE_INSTALL_PREFIX="C:\Qt\6.8 .1\msvc2022_64"
                  

                  I get the error

                  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
                  -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
                  -- Looking for pthread_create in pthreads
                  -- Looking for pthread_create in pthreads - not found
                  -- Looking for pthread_create in pthread
                  -- Looking for pthread_create in pthread - not found
                  

                  Is this a problem with version? I used the same method that had worked in version 6.7.3. If it's a version issue, will I have to wait for a new version to be released by PyQt6?

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @ThiagoSys said in QSqlDatabase: QMYSQL driver not loaded:

                  I get the error

                  I don't see any error here, just information on what features are found/not found.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  1
                  • T Offline
                    T Offline
                    ThiagoSys
                    wrote on last edited by
                    #10
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      See https://forum.qt.io/search?in=posts&term=sbom&matchWords=all&by=&categories=&searchChildren=false&hasTags=&replies=&repliesFilter=atleast&timeFilter=newer&timeRange=&sortBy=relevance&sortDirection=desc&showAs=posts

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      T 1 Reply Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        See https://forum.qt.io/search?in=posts&term=sbom&matchWords=all&by=&categories=&searchChildren=false&hasTags=&replies=&repliesFilter=atleast&timeFilter=newer&timeRange=&sortBy=relevance&sortDirection=desc&showAs=posts

                        T Offline
                        T Offline
                        ThiagoSys
                        wrote on last edited by
                        #12

                        @Christian-Ehrlicher

                        You said in one of the posts linked above to Update to 6.8.2 / 6.9.0
                        But when I run my code with plugin version 6.7.3 I got the following error
                        Cannot mix incompatible Qt library (6.7.3) with this library (6.8.1)

                        If I install version 6.8.2 wouldn't this incompatibility happen in the same way?

                        1 Reply Last reply
                        0
                        • Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          I also wrote that you can apply the patch...

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          T 1 Reply Last reply
                          0
                          • Christian EhrlicherC Christian Ehrlicher

                            I also wrote that you can apply the patch...

                            T Offline
                            T Offline
                            ThiagoSys
                            wrote on last edited by
                            #14

                            @Christian-Ehrlicher Can you provide me with an explanation on how to apply the patch?

                            1 Reply Last reply
                            0
                            • T Offline
                              T Offline
                              ThiagoSys
                              wrote on last edited by
                              #15

                              Can anyone tell me how to compile SBOM?

                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #16

                                From the looks of it, you can also disable the sbom. See this comment on the bug report.

                                As for patching, do you know how to apply a diff ?
                                If not, one possible solution is to just copy the two files from 6.8.2 into your current sources but I would encourage you to learn how to apply a patch.

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                T 1 Reply Last reply
                                0
                                • SGaistS SGaist

                                  From the looks of it, you can also disable the sbom. See this comment on the bug report.

                                  As for patching, do you know how to apply a diff ?
                                  If not, one possible solution is to just copy the two files from 6.8.2 into your current sources but I would encourage you to learn how to apply a patch.

                                  T Offline
                                  T Offline
                                  ThiagoSys
                                  wrote on last edited by
                                  #17

                                  @SGaist
                                  I tried to learn how to apply a patch but it's complicated, I'm Brazilian and I can't find much about it in Portuguese.
                                  About disabling sbom I tried adding the commands -DQT_GENERATE_SBOM=OFF and -no-sbom but it didn't change. I'm thinking about giving up and doing it the traditional way

                                  jsulmJ 1 Reply Last reply
                                  0
                                  • T ThiagoSys

                                    @SGaist
                                    I tried to learn how to apply a patch but it's complicated, I'm Brazilian and I can't find much about it in Portuguese.
                                    About disabling sbom I tried adding the commands -DQT_GENERATE_SBOM=OFF and -no-sbom but it didn't change. I'm thinking about giving up and doing it the traditional way

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #18

                                    @ThiagoSys What about this suggestion from @SGaist : "one possible solution is to just copy the two files from 6.8.2 into your current sources"?

                                    And applying patches isn't isn't complicated.

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

                                    T 1 Reply Last reply
                                    1
                                    • jsulmJ jsulm

                                      @ThiagoSys What about this suggestion from @SGaist : "one possible solution is to just copy the two files from 6.8.2 into your current sources"?

                                      And applying patches isn't isn't complicated.

                                      T Offline
                                      T Offline
                                      ThiagoSys
                                      wrote on last edited by
                                      #19

                                      @jsulm
                                      I don't know exactly which files I should copy and to which source

                                      1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by SGaist
                                        #20

                                        If you go to the patch linked in the bug report, you'll see the exact path of the two files that have been modified in qtbase.

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        1 Reply Last reply
                                        1

                                        • Login

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