Results 1 to 5 of 5

Thread: Qt database connection: QMYSQL driver not loaded

  1. #1
    Join Date
    Dec 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Qt database connection: QMYSQL driver not loaded

    I'm using Qt 5.5 with MSVC plugin. I want to simply connect to a database. The code is -
    Qt Code:
    1. QString hostName = "127.0.0.1";
    2. QString databaseName = "imagedatabase";
    3. QString userName = "demouser";
    4. QString userPass = "demopass";
    5.  
    6. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    7. db.setHostName(hostName);
    8. db.setDatabaseName(databaseName);
    9. db.setUserName(userName);
    10. db.setPassword(userPass);
    11.  
    12. bool ok = db.open();
    To copy to clipboard, switch view to plain text mode 

    But the following error occurs -

    Qt Code:
    1. QSqlDatabase: QMYSQL driver not loaded
    2. QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
    To copy to clipboard, switch view to plain text mode 

    Then following some suggestion in the web - I copied the qsqlmysql.dll, qsqlmysqld.dll,libmysql.dll, libmysqld.dll files to the project folder. -that didn't work. According to another thread here - I have to put mysqlclient.lib where my application executable is. But I use a wampserver mysql where I don't have a mysqlclient.lib file.
    How can I complete this simple task?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,722
    Thanks
    260
    Thanked 760 Times in 750 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Qt database connection: QMYSQL driver not loaded

    Sounds like you haven't read the documentation on How to Create Plugins and Deploying Plugins. And you probably haven't installed the MySQL Connector for C++ either.
    Last edited by d_stranz; 19th December 2015 at 04:59.

  3. #3
    Join Date
    Apr 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt database connection: QMYSQL driver not loaded

    Well, just for people arriving here in despair, you can ignore this rant, I'm sure you already read the documentation and yes, you don't need MySQL Connector for C++.
    You need this in the executable folder: libmysql.dll and qsqlmysql.dll

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,722
    Thanks
    260
    Thanked 760 Times in 750 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Qt database connection: QMYSQL driver not loaded

    Thank you for your polite and instructive comments. We look forward to your next 2,247 helpful posts over the next 8 years

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,679
    Thanks
    13
    Thanked 1,597 Times in 1,525 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt database connection: QMYSQL driver not loaded

    The Qt Mysql plugin should be placed in a directory "sqldrivers" that lives next to the main project executable. This is the app-specific default location searched for SQL plugins. The Mysql runtime library, which is not part of Qt, can be placed anywhere the standard Windows DLL search would look when it loads the plugin dll (on a dev machine this is often on the %PATH). For deployment it is usually most convenient to put it in the "sqldrivers" directory too.
    http://doc.qt.io/qt-5/windows-deploy...tml#qt-plugins

    If you do not have a full Mysql install to work from the Mysql Connector for C should contain the run time library:
    http://dev.mysql.com/downloads/connector/c/

Similar Threads

  1. QMYSQL driver not loaded
    By shadowCODE in forum Installation and Deployment
    Replies: 3
    Last Post: 21st December 2014, 20:21
  2. QMYSQL driver not loaded
    By robotics in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2011, 13:43
  3. QMYSQL driver not loaded
    By cydside in forum Qt Programming
    Replies: 4
    Last Post: 31st March 2010, 03:18
  4. QMYSQL driver not loaded
    By akhila in forum Newbie
    Replies: 1
    Last Post: 22nd February 2010, 19:24
  5. QMYSQL driver not loaded
    By sepehr in forum Qt Programming
    Replies: 12
    Last Post: 11th January 2009, 21:15

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.