Results 1 to 3 of 3

Thread: Running into many problems setting up Qt and QMYSQL (qmake won't run?)

  1. #1
    Join Date
    Jun 2019
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Running into many problems setting up Qt and QMYSQL (qmake won't run?)

    Hello All,

    I’m just starting out with Qt on Mac OSX 10.14.5 Mojave, and I’ve been having a terrible time getting past the issue “QMYSQL driver not loaded”. I know from my searching that this is something a lot of people have trouble with, and I’ve tried just about everything I found online. This morning I had to wipe everything on the computer, so I’m starting fresh without any leftovers from previous attempts. Because of this, I won't list out everything I've tried.
    Here’s what I’ve done today:

    -Installed MySQL Community Server 8.0.16 using the DMG installer.
    -Installed Xcode via the App Store
    -Installed Qt Open Source using the default installer on the qt.io downloads page; when prompted to choose components, chose under 5.12.3 “macOS” and “sources”, and left “Developer and Designer Tools” alone.

    Opening up Qt Creator works fine. I opened the ‘Books’ example project and it runs fine. But, when I add the line:
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    To copy to clipboard, switch view to plain text mode 

    I get the error:
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

    Anyway, I started to follow the guide here https://doc.qt.io/qt-5/sql-driver.html

    Qt Code:
    1. $ cd Qt/5.12.3/clang_64/plugins/sqldrivers/
    2. $ qmake -- MYSQL_PREFIX=/usr/local
    3. -bash: qmake: command not found
    To copy to clipboard, switch view to plain text mode 
    For whatever reason qmake didn't end up on the PATH so I added it and it seemed to work:
    Qt Code:
    1. $ echo $PATH
    2. /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
    3. $ export PATH=$PATH:/Users/ebm/Qt/5.12.3/clang_64/bin
    4. $ qmake --version
    5. QMake version 3.1
    6. Using Qt version 5.12.3 in /Users/ebm/Qt/5.12.3/clang_64/lib
    To copy to clipboard, switch view to plain text mode 
    but now when I try qmake -- MYSQL_PREFIX=/usr/local again, I just get the help menu.

    Qt Code:
    1. $ qmake -- MYSQL_PREFIX=/usr/local
    2. Usage: qmake [mode] [options] [files]
    3.  
    4. QMake has two modes, one mode for generating project files based on
    5. some heuristics, and the other for generating makefiles. Normally you
    6. shouldn't need to specify a mode, as makefile generation is the default
    7. mode for qmake, but you may use this to test qmake on an existing project
    To copy to clipboard, switch view to plain text mode 
    (etc)

    I don't get why this is happening. I definitely got this command to execute (albeit unsuccessfully) before I had to wipe my machine, but now it isn't actually doing anything. Why not?

    Any help is really appreciated. I'm totally new to all of this and I'm getting confused and kind of frustrated.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,072
    Thanks
    233
    Thanked 649 Times in 639 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Running into many problems setting up Qt and QMYSQL (qmake won't run?)

    You probably don't actually need to build the Qt MySQL driver. It was probably installed when you installed the default Qt for MacOS. The fact that available drivers shows you that a couple of flavors of QMYSQL are available indicates that.

    However, if the situation is anything like Windows, you need more than the Qt driver. You also need the MySQL client shared library on which the Qt driver depends. Available drivers only shows you that the Qt-side shared library exists. It doesn't tell you whether or not it can be fully instantiated, which means it must be able to load itself and all of the libraries it depends on. So, either the MySQL shared library wasn't installed when you installed the server, or it isn't on your PATH so isn't being loaded.

    Check the MySQL site where you got the server to see if the client library is also installed, what it is named, and where it is installed. If you can't find it, then it probably wasn't installed and you need to do that. If you do find it, then make sure it is on your PATH.

    Look for "Connector/C" or "Connector/C++" on the on the MySQL site.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    apocrita (20th June 2019)

  4. #3
    Join Date
    Jun 2019
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Running into many problems setting up Qt and QMYSQL (qmake won't run?)

    Quote Originally Posted by d_stranz View Post
    You probably don't actually need to build the Qt MySQL driver. It was probably installed when you installed the default Qt for MacOS. The fact that available drivers shows you that a couple of flavors of QMYSQL are available indicates that.

    However, if the situation is anything like Windows, you need more than the Qt driver. You also need the MySQL client shared library on which the Qt driver depends. Available drivers only shows you that the Qt-side shared library exists. It doesn't tell you whether or not it can be fully instantiated, which means it must be able to load itself and all of the libraries it depends on. So, either the MySQL shared library wasn't installed when you installed the server, or it isn't on your PATH so isn't being loaded.

    Check the MySQL site where you got the server to see if the client library is also installed, what it is named, and where it is installed. If you can't find it, then it probably wasn't installed and you need to do that. If you do find it, then make sure it is on your PATH.

    Look for "Connector/C" or "Connector/C++" on the on the MySQL site.
    Thanks so much for helping me!

    I found in my mysql installation, under usr/local/mysql/lib, a file named "libmysqlclient.dylib" and another named "libmysqlclient.21.dylib".
    Then I checked the libraries Qt is expecting:
    Qt Code:
    1. $ otool -L libqsqlmysql.dylib
    2. libqsqlmysql.dylib:
    3. libqsqlmysql.dylib (compatibility version 0.0.0, current version 0.0.0)
    4. @rpath/QtSql.framework/Versions/5/QtSql (compatibility version 5.12.0, current version 5.12.3)
    5. @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.12.0, current version 5.12.3)
    6. /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
    7. /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
    8. /usr/local/mysql/lib/libmysqlclient.20.dylib (compatibility version 20.0.0, current version 20.0.0)
    9. /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
    10. /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
    To copy to clipboard, switch view to plain text mode 
    So, line 7 shows that it wants libmysqlclient.20.dylib, but I have 21. I'm guessing this is the problem (or at least part of it!) but I am not sure how to tell it to look for the version I have.
    My PATH looks like this:
    Qt Code:
    1. /usr/local/mysql/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ebm/Qt/5.12.3/clang_64/bin:/usr/local/mysql/lib/
    To copy to clipboard, switch view to plain text mode 


    EDIT: I figured it out!

    I ran

    Qt Code:
    1. install_name_tool -change /usr/local/mysql/lib/libmysqlclient.20.dylib /usr/local/mysql/lib/libmysqlclient.dylib libqsqlmysql.dylib
    To copy to clipboard, switch view to plain text mode 
    and now I don't get that error anymore!!

    Thanks for the tip, this has been driving me up the wall for literal days
    Last edited by apocrita; 14th June 2019 at 21:06.

Similar Threads

  1. Running QMake and Make on different systems
    By mmangold in forum Qt Programming
    Replies: 4
    Last Post: 19th September 2015, 09:39
  2. Huge problems while installing QMYSQL driver
    By ZikO in forum Installation and Deployment
    Replies: 4
    Last Post: 21st August 2012, 19:56
  3. problems building the QMYSQL plugin on Windows 64 using MinGW 64
    By carpanta in forum Installation and Deployment
    Replies: 1
    Last Post: 24th April 2012, 20:13
  4. Help with qmake and pro setting
    By lni in forum Qt Programming
    Replies: 2
    Last Post: 28th February 2007, 10:02
  5. running qmake
    By exsto in forum Installation and Deployment
    Replies: 2
    Last Post: 15th July 2006, 17:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.