Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Can't working MYSQL database in qt (QSqlDatabase: available drivers: QSQLITE QODBC QPSQL)
Forum Updated to NodeBB v4.3 + New Features

Can't working MYSQL database in qt (QSqlDatabase: available drivers: QSQLITE QODBC QPSQL)

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
33 Posts 6 Posters 4.1k Views 1 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.
  • L Offline
    L Offline
    Lestev
    wrote on 22 Feb 2022, 13:29 last edited by
    #1

    Hi i'm trying solve the problem, i really hope that you can help me.

    first, i got this error:

    QSqlQuery::exec: database not open
    QSqlQuery::exec: database not open
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QPSQL

    I am trying all methods how solve this problem and always got an error -->

    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

    Screenshot 2022-02-22 at 16.24.52.png

    Screenshot 2022-02-22 at 16.24.09.png

    My purpose use database MYSQL in qt, please help me

    J 1 Reply Last reply 22 Feb 2022, 13:33
    0
    • L Lestev
      22 Feb 2022, 13:29

      Hi i'm trying solve the problem, i really hope that you can help me.

      first, i got this error:

      QSqlQuery::exec: database not open
      QSqlQuery::exec: database not open
      QSqlDatabase: QMYSQL driver not loaded
      QSqlDatabase: available drivers: QSQLITE QODBC QPSQL

      I am trying all methods how solve this problem and always got an error -->

      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

      Screenshot 2022-02-22 at 16.24.52.png

      Screenshot 2022-02-22 at 16.24.09.png

      My purpose use database MYSQL in qt, please help me

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 22 Feb 2022, 13:33 last edited by
      #2

      @Lestev You need to build qmysql plug-in, see https://doc.qt.io/qt-5/sql-driver.html
      Because of the license it is not delivered with Qt binaries.

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 22 Feb 2022, 13:36 last edited by
        #3

        Hi and welcome to devnet,

        In addition to @jsulm, you need to grab the Qt sources matching the one that you have installed. And since you are using Qt 6.2 you should follow the instructions provided in the corresponding documentation which does not use qmake at all.

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

        L 1 Reply Last reply 22 Feb 2022, 14:06
        1
        • S SGaist
          22 Feb 2022, 13:36

          Hi and welcome to devnet,

          In addition to @jsulm, you need to grab the Qt sources matching the one that you have installed. And since you are using Qt 6.2 you should follow the instructions provided in the corresponding documentation which does not use qmake at all.

          L Offline
          L Offline
          Lestev
          wrote on 22 Feb 2022, 14:06 last edited by
          #4

          @SGaist thanks, but i got error Screenshot 2022-02-22 at 17.04.56.png

          J 1 Reply Last reply 22 Feb 2022, 14:33
          0
          • L Lestev
            22 Feb 2022, 14:06

            @SGaist thanks, but i got error Screenshot 2022-02-22 at 17.04.56.png

            J Offline
            J Offline
            JonB
            wrote on 22 Feb 2022, 14:33 last edited by
            #5

            @Lestev
            Whatever instructions you are following, you are not supposed to literally type:

            qt-cmake -G Ninja <qt_installation_path>/Users/...
            

            hence the error message mentioning

            no such file or directory: qt_installation_path
            

            ...

            1 Reply Last reply
            1
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 22 Feb 2022, 14:43 last edited by
              #6

              Also, did you install cmake ? From one of your errors it seems not...

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

              L 1 Reply Last reply 22 Feb 2022, 16:35
              1
              • S SGaist
                22 Feb 2022, 14:43

                Also, did you install cmake ? From one of your errors it seems not...

                L Offline
                L Offline
                Lestev
                wrote on 22 Feb 2022, 16:35 last edited by
                #7

                @SGaist I install cmake but error: Screenshot 2022-02-22 at 19.34.02.png

                J 1 Reply Last reply 22 Feb 2022, 18:02
                0
                • L Lestev
                  22 Feb 2022, 16:35

                  @SGaist I install cmake but error: Screenshot 2022-02-22 at 19.34.02.png

                  J Offline
                  J Offline
                  JonB
                  wrote on 22 Feb 2022, 18:02 last edited by JonB
                  #8

                  @Lestev
                  I think you have typed an incorrect character in the command you are trying to copy from somewhere? You have a > where I do not think you should have, maybe even a < too. Could you please

                  • Copy and paste all that text here instead of a screenshot, please; and
                  • Show where/what exactly it is that is telling you what to type as the command.
                  L 1 Reply Last reply 22 Feb 2022, 18:41
                  0
                  • J JonB
                    22 Feb 2022, 18:02

                    @Lestev
                    I think you have typed an incorrect character in the command you are trying to copy from somewhere? You have a > where I do not think you should have, maybe even a < too. Could you please

                    • Copy and paste all that text here instead of a screenshot, please; and
                    • Show where/what exactly it is that is telling you what to type as the command.
                    L Offline
                    L Offline
                    Lestev
                    wrote on 22 Feb 2022, 18:41 last edited by Lestev
                    #9

                    @JonB Hi, thanks, commands:

                    mkdir build-sqldrivers

                    cd build-sqldrivers

                    qt-cmake -G Ninja <qt_installation_path>/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DMySQL_INCLUDE_DIR="/usr/local/mysql/include" -DMySQL_LIBRARY="/usr/local/mysql/lib/libmysqlclient.<so|dylib>"

                    cmake --build .

                    cmake --install .

                    https://doc.qt.io/qt-6/sql-driver.html#qmysql

                    Screenshot 2022-02-22 at 21.40.10.png

                    Screenshot 2022-02-22 at 21.40.59.png

                    I want to connect to database MYSQL, but it is error bother me)...

                    J 1 Reply Last reply 22 Feb 2022, 18:56
                    0
                    • L Lestev
                      22 Feb 2022, 18:41

                      @JonB Hi, thanks, commands:

                      mkdir build-sqldrivers

                      cd build-sqldrivers

                      qt-cmake -G Ninja <qt_installation_path>/Src/qtbase/src/plugins/sqldrivers -DCMAKE_INSTALL_PREFIX=<qt_installation_path>/<platform> -DMySQL_INCLUDE_DIR="/usr/local/mysql/include" -DMySQL_LIBRARY="/usr/local/mysql/lib/libmysqlclient.<so|dylib>"

                      cmake --build .

                      cmake --install .

                      https://doc.qt.io/qt-6/sql-driver.html#qmysql

                      Screenshot 2022-02-22 at 21.40.10.png

                      Screenshot 2022-02-22 at 21.40.59.png

                      I want to connect to database MYSQL, but it is error bother me)...

                      J Offline
                      J Offline
                      JonB
                      wrote on 22 Feb 2022, 18:56 last edited by JonB
                      #10

                      @Lestev
                      I asked you to copy & paste the command you showed yourself issuing and going wrong in your previous post. The whole of your terminal window's input/output. You now seem to be showing something totally different and unrelated, and not even mentioning that. I don't know what you want help with. Please try to ask some question and stick with it.

                      L 1 Reply Last reply 22 Feb 2022, 19:20
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 22 Feb 2022, 19:18 last edited by
                        #11

                        It's one thing to copy commands verbatim, it's another to truly understand what is going on. From what you shown, the backend was at least not installed and from the looks of it, not even built.

                        Did you check that you have the MySQL client library installed ?

                        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
                        • J JonB
                          22 Feb 2022, 18:56

                          @Lestev
                          I asked you to copy & paste the command you showed yourself issuing and going wrong in your previous post. The whole of your terminal window's input/output. You now seem to be showing something totally different and unrelated, and not even mentioning that. I don't know what you want help with. Please try to ask some question and stick with it.

                          L Offline
                          L Offline
                          Lestev
                          wrote on 22 Feb 2022, 19:20 last edited by
                          #12

                          @JonB my question is simple how can i create a file libqsqlmysql.dylib if i keep getting error when calling qmake:

                          I follow the documentation on how to create libqsqlmysql.dylib:

                          Screenshot 2022-02-22 at 22.11.26.png

                          the first is that I choose a folder
                          Screenshot 2022-02-22 at 22.12.57.png

                          after i go to terminal
                          Screenshot 2022-02-22 at 22.16.21.png
                          How can i fix this error?

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 22 Feb 2022, 19:33 last edited by
                            #13

                            By following the instructions from Qt 6 as you were already explained. Instructions which makes no use of qmake as Qt 6 uses cmake as build system.
                            By not just copy/pasting the commands shown but doing the appropriate substitutions since there are placeholders in the instructions shown in the documentation.
                            By ensuring that you have the correct dependencies installed.
                            By checking the configure log.
                            By checking the build log.

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

                            L 1 Reply Last reply 23 Feb 2022, 07:03
                            3
                            • S SGaist
                              22 Feb 2022, 19:33

                              By following the instructions from Qt 6 as you were already explained. Instructions which makes no use of qmake as Qt 6 uses cmake as build system.
                              By not just copy/pasting the commands shown but doing the appropriate substitutions since there are placeholders in the instructions shown in the documentation.
                              By ensuring that you have the correct dependencies installed.
                              By checking the configure log.
                              By checking the build log.

                              L Offline
                              L Offline
                              Lestev
                              wrote on 23 Feb 2022, 07:03 last edited by
                              #14

                              @SGaist So i followed documentation :
                              Screenshot 2022-02-23 at 10.00.44.png

                              Screenshot 2022-02-23 at 10.00.16.png

                              but the command gave me an error

                              J 1 Reply Last reply 23 Feb 2022, 07:12
                              0
                              • L Lestev
                                23 Feb 2022, 07:03

                                @SGaist So i followed documentation :
                                Screenshot 2022-02-23 at 10.00.44.png

                                Screenshot 2022-02-23 at 10.00.16.png

                                but the command gave me an error

                                J Offline
                                J Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on 23 Feb 2022, 07:12 last edited by
                                #15

                                @Lestev You should really start to CAREFULLY read what others write and also try to understand what you are doing!
                                You are still using .<so|dylib> in your command and it should be actually apparent that you should replace it by what your platform requires (.dylib on Mac).

                                You also should remove "-G Ninja" if you do not have Ninja.

                                Also you were asked to post TEXT not pictures, but you keep posting pictures. Is there a reason for that?

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

                                L 1 Reply Last reply 23 Feb 2022, 08:13
                                1
                                • J jsulm
                                  23 Feb 2022, 07:12

                                  @Lestev You should really start to CAREFULLY read what others write and also try to understand what you are doing!
                                  You are still using .<so|dylib> in your command and it should be actually apparent that you should replace it by what your platform requires (.dylib on Mac).

                                  You also should remove "-G Ninja" if you do not have Ninja.

                                  Also you were asked to post TEXT not pictures, but you keep posting pictures. Is there a reason for that?

                                  L Offline
                                  L Offline
                                  Lestev
                                  wrote on 23 Feb 2022, 08:13 last edited by
                                  #16

                                  @jsulm wow! Thank you very much, I did this and succeeded, but the error remained, I added install_name_tool -change /usr/local/mysql-8.0.25-macos11-x86_64/lib/libmysqlclient.21.dylib /usr/local/mysql-8.0 . 25-macos11-x86_64/lib/libmysqlclient.21.dylib/Users/migellestv/Qt/6.2.3/macos/plugins/sqldrivers/libqsqlmysql.dylib

                                  and I succeeded, but error remained:

                                  QSqlQuery::exec: database not open
                                  QSqlQuery::exec: database not open
                                  QSqlDatabase: QMYSQL driver not loaded
                                  QSqlDatabase: available drivers: QSQLITE QODBC QPSQL

                                  Why if i added install_name_tool?

                                  J 1 Reply Last reply 23 Feb 2022, 08:22
                                  0
                                  • L Lestev
                                    23 Feb 2022, 08:13

                                    @jsulm wow! Thank you very much, I did this and succeeded, but the error remained, I added install_name_tool -change /usr/local/mysql-8.0.25-macos11-x86_64/lib/libmysqlclient.21.dylib /usr/local/mysql-8.0 . 25-macos11-x86_64/lib/libmysqlclient.21.dylib/Users/migellestv/Qt/6.2.3/macos/plugins/sqldrivers/libqsqlmysql.dylib

                                    and I succeeded, but error remained:

                                    QSqlQuery::exec: database not open
                                    QSqlQuery::exec: database not open
                                    QSqlDatabase: QMYSQL driver not loaded
                                    QSqlDatabase: available drivers: QSQLITE QODBC QPSQL

                                    Why if i added install_name_tool?

                                    J Offline
                                    J Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 23 Feb 2022, 08:22 last edited by
                                    #17

                                    @Lestev Did you also do this:

                                    cmake --build .
                                    cmake --install .
                                    

                                    ?
                                    https://doc.qt.io/qt-6/sql-driver.html#qmysql

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

                                    L 1 Reply Last reply 23 Feb 2022, 09:02
                                    0
                                    • J jsulm
                                      23 Feb 2022, 08:22

                                      @Lestev Did you also do this:

                                      cmake --build .
                                      cmake --install .
                                      

                                      ?
                                      https://doc.qt.io/qt-6/sql-driver.html#qmysql

                                      L Offline
                                      L Offline
                                      Lestev
                                      wrote on 23 Feb 2022, 09:02 last edited by
                                      #18

                                      @jsulm said in Can't working MYSQL database in qt (QSqlDatabase: available drivers: QSQLITE QODBC QPSQL):

                                      Did you also do this:

                                      Yes i successed :

                                      cmake --build .
                                      [9/11] Linking CXX shared module plugins/sqldrivers/libqsqlmysql.dylib
                                      ld: warning: linking against a dylib which is not safe for use in application extensions: /usr/local/mysql/lib/libmysqlclient.dylib
                                      [11/11] Linking CXX shared module plugins/sqldrivers/libqsqlite.dylib
                                      migellestev@Migels-MacBook-Pro build-sqldrivers % cmake --install .
                                      -- Install configuration: "RelWithDebInfo"
                                      -- Installing: /Users/migellestev/Qt/6.2.3/macos/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginConfig.cmake
                                      -- Installing: /Users/migellestev/Qt/6.2.3/macos/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginConfigVersion.cmake
                                      -- Installing: /Users/migellestev/Qt/6.2.3/macos/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginConfigVersionImpl.cmake
                                      etc

                                      J 1 Reply Last reply 23 Feb 2022, 09:13
                                      0
                                      • L Lestev
                                        23 Feb 2022, 09:02

                                        @jsulm said in Can't working MYSQL database in qt (QSqlDatabase: available drivers: QSQLITE QODBC QPSQL):

                                        Did you also do this:

                                        Yes i successed :

                                        cmake --build .
                                        [9/11] Linking CXX shared module plugins/sqldrivers/libqsqlmysql.dylib
                                        ld: warning: linking against a dylib which is not safe for use in application extensions: /usr/local/mysql/lib/libmysqlclient.dylib
                                        [11/11] Linking CXX shared module plugins/sqldrivers/libqsqlite.dylib
                                        migellestev@Migels-MacBook-Pro build-sqldrivers % cmake --install .
                                        -- Install configuration: "RelWithDebInfo"
                                        -- Installing: /Users/migellestev/Qt/6.2.3/macos/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginConfig.cmake
                                        -- Installing: /Users/migellestev/Qt/6.2.3/macos/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginConfigVersion.cmake
                                        -- Installing: /Users/migellestev/Qt/6.2.3/macos/lib/cmake/Qt6Sql/Qt6QMYSQLDriverPluginConfigVersionImpl.cmake
                                        etc

                                        J Offline
                                        J Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on 23 Feb 2022, 09:13 last edited by
                                        #19

                                        @Lestev OK, then we need to debug now.
                                        Do this on console:

                                        • Go to the build folder of your application
                                        • Do: export QT_DEBUG_PLUGINS=1
                                        • Run your app from the terminal
                                        • Copy paste the output from terminal to here

                                        You can also set QT_DEBUG_PLUGINS in Run settings of your project in QtCreator.
                                        https://doc.qt.io/qt-5/debug.html

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

                                        L 1 Reply Last reply 23 Feb 2022, 09:52
                                        0
                                        • J jsulm
                                          23 Feb 2022, 09:13

                                          @Lestev OK, then we need to debug now.
                                          Do this on console:

                                          • Go to the build folder of your application
                                          • Do: export QT_DEBUG_PLUGINS=1
                                          • Run your app from the terminal
                                          • Copy paste the output from terminal to here

                                          You can also set QT_DEBUG_PLUGINS in Run settings of your project in QtCreator.
                                          https://doc.qt.io/qt-5/debug.html

                                          L Offline
                                          L Offline
                                          Lestev
                                          wrote on 23 Feb 2022, 09:52 last edited by Lestev
                                          #20

                                          @jsulm Thanks, i get it, but how i can use run in terminal project?, i wrote:

                                          migellestev@Migels-MacBook-Pro forBeginner % c++ main.cpp
                                          main.cpp:1:10: fatal error: 'QGuiApplication' file not found
                                          #include <QGuiApplication>
                                          ^~~~~~~~~~~~~~~~~
                                          1 error generated.

                                          J 2 Replies Last reply 23 Feb 2022, 09:55
                                          0

                                          5/33

                                          22 Feb 2022, 14:33

                                          28 unread
                                          • Login

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