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: What am I doing wrong?

QSqlDatabase: QMYSQL driver not loaded: What am I doing wrong?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 588 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.
  • M Offline
    M Offline
    Menre
    wrote on last edited by
    #1

    Hello Folks,

    Kindly help me please.

    I am learning to connect to MySQL on XAMPP with QT Creator. I followed a video tutorial and did exactly as they did to make it work, but it did not work for me. Instead, I got the error message below. I have made effort to fix it myself by searching the web, but with no luck yet. Here is the error message.

    "QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7
    Unable to connect to the database check your connection details."

    I downloaded the MySQL connector - c, put it on a folder on my desktop and added it as an external library before running it.

    The files below are my two files for the code.

    1. ----------------The main.cpp-----------------------

    #include <QCoreApplication>
    #include <QtSql/QtSql>
    #include <QtSql/QSqlDatabase>
    #include <QtSql/QSqlQuery>

    //Add the i/o stream
    #include <iostream>
    using namespace std;

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);

    //Create a database connection
    

    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setUserName("root");
    db.setPassword("");
    db.setDatabaseName("qtdatabase");

    //Test the connection
    if(db.open()) {
    cout << "Database connected successfully" << endl;

    } else {

    cout << "Unable to connect to the database check your connection details." << endl;
    

    }

    return a.exec();
    

    }

    1. -----------The mysqlconnect.pro file--------------

    QT += core
    QT += sql
    QT -= gui

    CONFIG += c++11 console

    TARGET = mysqlconnect

    CONFIG -= app_bundle

    SOURCES +=
    main.cpp

    Default rules for deployment.

    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target

    win32: LIBS += -L$$PWD/../../../../Users/user/Desktop/lib/ -llibmysql

    INCLUDEPATH += $$PWD/../../../../Users/user/Desktop
    DEPENDPATH += $$PWD/../../../../Users/user/Desktop

    I will really appreciate your help please.

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

      Hi,

      This question has been asked many times already. Did you take the time to search and go through the numerous forum threads about this topic ?

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

      M 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        This question has been asked many times already. Did you take the time to search and go through the numerous forum threads about this topic ?

        M Offline
        M Offline
        Menre
        wrote on last edited by
        #3

        @SGaist I have read many posts about this issue and some get one more confused than one was before reading them. Even doing some of their suggestions about downloading some .dll files and copying them to a folder do not help. Do you have a particular post or advice in mind that helps?

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

          So did you actually run Dependency Walker to see of the Qt mysql plugins finds all needed dependencies?

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

          M 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            So did you actually run Dependency Walker to see of the Qt mysql plugins finds all needed dependencies?

            M Offline
            M Offline
            Menre
            wrote on last edited by
            #5

            @Christian-Ehrlicher No, I did not run it. How do I do that? All the posts that I have been reading have QMYSQL as one of the available drivers, but mine doesn't have it. Will running Dependency Walker check that? What I have as available drivers is the line below please.
            'QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7'.

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

              I downloaded the MySQL connector - c, put it on a folder on my desktop and added it as an external library before running it.

              You did you actually follow https://doc.qt.io/qt-5/sql-driver.html#qmysql to build the plugin?

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

              M 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                I downloaded the MySQL connector - c, put it on a folder on my desktop and added it as an external library before running it.

                You did you actually follow https://doc.qt.io/qt-5/sql-driver.html#qmysql to build the plugin?

                M Offline
                M Offline
                Menre
                wrote on last edited by
                #7

                @Christian-Ehrlicher I am now asking myself why is something so simple (as per your response) so dificult for me to do. I have visited the link you sent. What is the right way to implement the line below with my code please?
                "To use the embedded MySQL server, simply link the Qt plugin to libmysqld instead of libmysqlclient. This can be done by adding MYSQL_LIBS=-lmysqld to the configure command line."

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

                  @Menre said in QSqlDatabase: QMYSQL driver not loaded: What am I doing wrong?:

                  implement the line below with my code please?

                  so what did you do until now? How did you configure the plugin? Please show use the output (as text, no pictures please)

                  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
                  0

                  • Login

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