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. [MYSQL-Qt] Create plugin MYSQL for Qt on MAC
QtWS25 Last Chance

[MYSQL-Qt] Create plugin MYSQL for Qt on MAC

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 14 Posters 6.8k Views
  • 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.
  • Q Offline
    Q Offline
    Quang Phu
    wrote on 4 Sept 2019, 17:27 last edited by Quang Phu 9 Apr 2019, 17:30
    #1

    Hi all,
    I have just created plugin MYSQL for Qt works on Mac, but it takes much time to handle issues during creating. Therefore, this topic will give some instruction how to do that.

    1. Install Qt and mysql, this is info of my device and tool version
      MacOs: Mojave 10.14.6
      Qt : 5.13.0 (latest)
      Mysql : 8.0.17

    2. Default, after installation, QMYSQL haven't been installed yet, so if you try to add database from command:
      QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
      Qt would report error:
      QSqlDatabase: QMYSQL driver not loaded
      QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7

    3. So we have to install plugin and follow documentation we do this:
      cd $QTDIR/Src/qtbase/src/plugins/sqldrivers
      qmake -- MYSQL_PREFIX=/usr/local/mysql
      make sub-mysql

      Note: here we pass "/usr/local/mysql" because it's location folder of mysql after installing.
      Then, we cd to mysql folder (folder inside sqldrivers) and make plugin through 2 commands
      qmake
      make install

      After this step, in folder $QTDIR/clang_64/plugins/sqldriver would have files of libqsqlmysql like this
      0_1567616296619_Screen Shot 2019-09-04 at 11.55.51 PM.png
      Now we can see info of this plugin with command:
      otool -L libqsqlmysql.dylib
      This is my case:
      0_1567616484458_Screen Shot 2019-09-05 at 12.01.14 AM.png

    4. We can see, at version 5.13.0, Qt uses libmysqlclient.21.dylib so we have use command install_name_tool -change to link qt lib and mysql lib, this is my case:
      install_name_tool -change /usr/local/mysql/lib/libmysqlclient.20.dylib /usr/local/mysql-5.7.27-macos10.14-x86_64/lib/libmysqlclient.20.dylib /Users/buiquangphu/Qt5.13.0/5.13.0/clang_64/plugins/sqldrivers/libqsqlmysql.dylib

    5. Now, set up is done, we open qt and rebuild then run program:
      If still has errors like this,
      QSqlDatabase: QMYSQL driver not loaded
      QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
      -> it means QMYSQL is now available bot not loaded
      You can put variable QT_DEBUG_PLUGINS = 1 in environment variable to see what happen with plugin, and this case, we got
      0_1567617328204_Screen Shot 2019-09-05 at 12.15.11 AM.png
      To fix, just add environment variable:
      DYLD_LIBRARY_PATH = /usr/local/mysql/lib/
      and error would disappear
      Problem was resolved

    I am new with qt but I think this info could be useful for someone else to reduce time for searching solution.
    Thanks!

    1 Reply Last reply
    0
    • J Offline
      J Offline
      James Hankins
      wrote on 16 Sept 2019, 01:22 last edited by
      #2

      This helped a bunch for MacOS, do you have a similar walk through for Windows? I've been attempting with msvc and getting a:

      Microsoft (R) Program Maintenance Utility Version 14.16.27034.0
      Copyright (C) Microsoft Corporation. All rights reserved.

      NMAKE : fatal error U1073: don't know how to make 'sub-mysql'
      Stop.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Quang Phu
        wrote on 17 Sept 2019, 02:50 last edited by Quang Phu
        #3

        Hi @James-Hankins,
        I haven't tried on Windows yet. but I think you can take a look with this post
        https://forum.qt.io/topic/96506/qtdriver-not-load
        May it help.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          James Hankins
          wrote on 21 Sept 2019, 16:21 last edited by
          #4

          Thanks, I was able to get the plugin built. I opened up a separate topic here:

          Just sorting out now that the build of the plugin succeeded (which was due to a prompt issue on my side selecting the standard VS prompt vs the 64bit prompt) how to get my test project to use it. I've got that discussion going on within the above linked topic.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            emiliano23
            wrote on 2 Oct 2019, 04:46 last edited by
            #5

            I am unable to run the following command:
            make sub-mysql

            Why is this?

            J 1 Reply Last reply 2 Oct 2019, 06:16
            0
            • E emiliano23
              2 Oct 2019, 04:46

              I am unable to run the following command:
              make sub-mysql

              Why is this?

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 2 Oct 2019, 06:16 last edited by
              #6

              @emiliano23 said in [MYSQL-Qt] Create plugin MYSQL for Qt on MAC:

              Why is this?

              Please provide more information.
              What happens if you try to execute this command?

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

              E 1 Reply Last reply 2 Oct 2019, 23:30
              0
              • J jsulm
                2 Oct 2019, 06:16

                @emiliano23 said in [MYSQL-Qt] Create plugin MYSQL for Qt on MAC:

                Why is this?

                Please provide more information.
                What happens if you try to execute this command?

                E Offline
                E Offline
                emiliano23
                wrote on 2 Oct 2019, 23:30 last edited by
                #7

                @jsulm
                After running with success
                qmake -- MYSQL_PREFIX=/usr/local/mysql
                I execute the command
                make sub-mysql

                And the output is
                make: *** No rule to make target `sub-mysql'. Stop.

                1 Reply Last reply
                0
                • Q Offline
                  Q Offline
                  Quang Phu
                  wrote on 3 Oct 2019, 00:52 last edited by Quang Phu 10 Mar 2019, 06:11
                  #8

                  Hi @emiliano23,
                  Did you install mysql on your Mac?
                  If installed, please check correct install path and make sure you run these command in correct directory ($QTDIR/Src/qtbase/src/plugins/sqldrivers)

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 3 Oct 2019, 07:22 last edited by
                    #9

                    Make sure to remove the old config.cache file and qmake actually is running the config checks: https://forum.qt.io/topic/106905/what-is-current-2019-recommended-process-complete-for-building-a-mysql-driver-for-use-with-qt-on-windows/5

                    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
                    • O Offline
                      O Offline
                      overmatch
                      wrote on 9 Nov 2019, 16:05 last edited by
                      #10

                      i tried, and almost every step is absolutely like yours, but at last step, i still get "drivers not loaded"

                      SGaistS M 2 Replies Last reply 9 Nov 2019, 19:42
                      0
                      • O overmatch
                        9 Nov 2019, 16:05

                        i tried, and almost every step is absolutely like yours, but at last step, i still get "drivers not loaded"

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 9 Nov 2019, 19:42 last edited by
                        #11

                        @overmatch A maybe silly question but did you call make install at the end ?

                        What do you get if you start the application with the QT_DEBUG_PLUGINS environment variable set to 1 ?

                        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
                        • E Offline
                          E Offline
                          EdBatt
                          wrote on 1 May 2020, 10:01 last edited by
                          #12

                          @Quang-Phu said in [MYSQL-Qt] Create plugin MYSQL for Qt on MAC:

                          /usr/local/mysql/lib/

                          Brilliant, I have been beating my head against the wall on this for a week or so before finding your post. Worked like a charm...thank you so much for taking the time to share.

                          1 Reply Last reply
                          0
                          • I Offline
                            I Offline
                            Imon
                            wrote on 26 Aug 2020, 13:40 last edited by Imon
                            #13

                            Could anyone tell me where/how to add the environment variable"DYLD_LIBRARY_PATH"??
                            I am using qt5.14.2 and I couldn’t figure out how to add it

                            SGaistS 1 Reply Last reply 26 Aug 2020, 18:14
                            0
                            • I Imon
                              26 Aug 2020, 13:40

                              Could anyone tell me where/how to add the environment variable"DYLD_LIBRARY_PATH"??
                              I am using qt5.14.2 and I couldn’t figure out how to add it

                              SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 26 Aug 2020, 18:14 last edited by
                              #14

                              @Imon hi and welcome to devnet,

                              If using Qt Creator, go to the Run part of the Project panel.

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

                              I 1 Reply Last reply 27 Aug 2020, 08:46
                              0
                              • SGaistS SGaist
                                26 Aug 2020, 18:14

                                @Imon hi and welcome to devnet,

                                If using Qt Creator, go to the Run part of the Project panel.

                                I Offline
                                I Offline
                                Imon
                                wrote on 27 Aug 2020, 08:46 last edited by
                                #15

                                @SGaist
                                Thank you very much. I found it, it was assigned to a different dir, and it works

                                1 Reply Last reply
                                0
                                • E Offline
                                  E Offline
                                  Eternus
                                  wrote on 27 Aug 2020, 09:44 last edited by Eternus
                                  #16

                                  @Quang-Phu said in [MYSQL-Qt] Create plugin MYSQL for Qt on MAC:

                                  make sub-mysql

                                  i stopped on. this he says me :
                                  macbook@MacBook-Pro-uzivatela-Macbook sqldrivers % make sub-mysql
                                  make: *** No rule to make target `sub-mysql'. Stop.
                                  macbook@MacBook-Pro-uzivatela-Macbook sqldrivers %

                                  me sqldrivers folder:
                                  Screenshot 2020-08-27 at 11.45.18.png

                                  SGaistS 1 Reply Last reply 27 Aug 2020, 18:37
                                  0
                                  • E Eternus
                                    27 Aug 2020, 09:44

                                    @Quang-Phu said in [MYSQL-Qt] Create plugin MYSQL for Qt on MAC:

                                    make sub-mysql

                                    i stopped on. this he says me :
                                    macbook@MacBook-Pro-uzivatela-Macbook sqldrivers % make sub-mysql
                                    make: *** No rule to make target `sub-mysql'. Stop.
                                    macbook@MacBook-Pro-uzivatela-Macbook sqldrivers %

                                    me sqldrivers folder:
                                    Screenshot 2020-08-27 at 11.45.18.png

                                    SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on 27 Aug 2020, 18:37 last edited by
                                    #17

                                    @Eternus you are already getting answered in your thread. Please don't pile up in other threads.

                                    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
                                    • H Offline
                                      H Offline
                                      Hang Zhang
                                      wrote on 24 Feb 2021, 12:58 last edited by
                                      #18

                                      Thanks a lot. I fixed my problem in 1hour due to this topic.

                                      1 Reply Last reply
                                      0
                                      • O overmatch
                                        9 Nov 2019, 16:05

                                        i tried, and almost every step is absolutely like yours, but at last step, i still get "drivers not loaded"

                                        M Offline
                                        M Offline
                                        MuGongZi
                                        wrote on 5 Apr 2021, 15:28 last edited by
                                        #19

                                        @overmatch have you solve this problem ,i have the same problem

                                        1 Reply Last reply
                                        0
                                        • L Offline
                                          L Offline
                                          losimen
                                          wrote on 29 Sept 2022, 20:12 last edited by
                                          #20
                                          This post is deleted!
                                          1 Reply Last reply
                                          0

                                          • Login

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