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. [SOLVED]MySQL driver
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]MySQL driver

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.9k 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.
  • G Offline
    G Offline
    gpuckett54
    wrote on last edited by
    #1

    I know this is subject has been beat to death and I have gone through all the posts regarding MySQL drivers. It appears that the usual solution is to rebuild the drivers. I really don't have that option.

    I have Qt v5.3.1 MVSC2010 opengl 32-bit installed on Windows 7. I have been using sqllite with no problems other than lousy performance. I would like to switch to MySQL for the better tools and, hopefully, better performance. My goal is to use MySQL embedded but for the moment I just want to access the currently running server. The MySQL server that is running on localhost is 64-bit, but I downloaded the 32-bit version of MySQL v5.5 for compatibility with my application.

    The database drivers were installed as a part of the pre-compiled install of Qt and the MySQL driver is in the same directory as the sqllite driver. Since sqllite was working fine I am assuming that my directory configuration is ok.

    libmysql.dll is in the lib directory of the MySQL install so I added that directory to the path environment variable.

    I am just attempting at the point to read an existing table from the server and display some results. My pro file is:

    @QT += core
    QT -= gui
    QT += webkit webkitwidgets
    QT += sql
    TARGET = TestMySQLExample
    CONFIG += console
    TEMPLATE = app
    INCLUDEPATH += "C:\Progra~2\MySQL\MySQL~1.5\include"
    LIBPATH += "C:\Progra~2\MySQL\MySQL~1.5\lib"
    SOURCES += main.cpp@

    main.cpp contains:

    @#include <QCoreApplication>
    #include <QApplication>
    #include <QtSql/QSql>
    #include <QtSql/QSqlDatabase>
    #include <QtSql/QSqlDriver>
    #include <QtSql/QSqlQuery>
    #include <QtSql/QSqlError>
    #include <QDebug>

    bool createConnection();

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    if (!createConnection()){

        qDebug() << "Not connected!";
        return 1;
    }
    else{
    
        qDebug() << "Connected!";
    
        QSqlQuery query;
        query.exec&#40;"SELECT parcel_id FROM parcel_tbl"&#41;;
        int cnt = 0;
    
        while (query.next(&#41; && ++cnt < 100) {
            QString parcelID = query.value(0).toString();
            qDebug() << "parcel_id:" << parcelID;
        }
    
        return 0;
    }
    
    return app.exec&#40;&#41;;
    

    }

    bool createConnection(){
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL","CAMADB");
    if(!db.isValid()) {
    qDebug() << "Did not get a good connection to MySQL ";
    return false;
    }

    db.setHostName("localhost");
    db.setDatabaseName("cama");
    db.setUserName("root");
    db.setPassword("cama123");
    if (!db.open()) {
        qDebug() << "Database error occurred";
        return false;
    }
    return true;
    

    }
    @

    When I attempt to test the code I get:

    @QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
    Did not get a good connection to MySQL
    Not connected!@

    I have output from plugin debug but it makes this post too long. I'll follow up with that.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gpuckett54
      wrote on last edited by
      #2

      I turned plugin debug on and get the following when I test:

      @QFactoryLoader::QFactoryLoader() checking directory path "C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers" ...
      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlite.dll"
      Found metadata in lib C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlite.dll, metadata=
      {
      "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
      "MetaData": {
      "Keys": [
      "QSQLITE"
      ]
      },
      "className": "QSQLiteDriverPlugin",
      "debug": false,
      "version": 328449
      }

      "The plugin 'C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlite.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)"
      not a plugin
      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlited.dll"
      Found metadata in lib C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlited.dll, metadata=
      {
      "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
      "MetaData": {
      "Keys": [
      "QSQLITE"
      ]
      },
      "className": "QSQLiteDriverPlugin",
      "debug": true,
      "version": 328449
      }

      Got keys from plugin meta data ("QSQLITE")
      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlited.pdb"
      "Plugin verification data mismatch in 'C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlited.pdb'"
      not a plugin
      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlmysql.dll"
      Found metadata in lib C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlmysql.dll, metadata=
      {
      "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
      "MetaData": {
      "Keys": [
      "QMYSQL3",
      "QMYSQL"
      ]
      },
      "className": "QMYSQLDriverPlugin",
      "debug": false,
      "version": 328449
      }

      "The plugin 'C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlmysql.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)"
      not a plugin
      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlmysqld.dll"
      Found metadata in lib C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlmysqld.dll, metadata=
      {
      "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
      "MetaData": {
      "Keys": [
      "QMYSQL3",
      "QMYSQL"
      ]
      },
      "className": "QMYSQLDriverPlugin",
      "debug": true,
      "version": 328449
      }

      Got keys from plugin meta data ("QMYSQL3", "QMYSQL")
      QFactoryLoader::QFactoryLoader() looking at "C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlmysqld.pdb"
      "Plugin verification data mismatch in 'C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlmysqld.pdb'"
      not a plugin

      loaded library "C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlmysqld.dll"
      QLibraryPrivate::loadPlugin failed on "C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlmysqld.dll" : "Cannot load library C:/Qt/Qt5.3.1/5.3/msvc2010_opengl/plugins/sqldrivers/qsqlmysqld.dll: "
      QSqlDatabase: QMYSQL driver not loaded@

      I see what looks to me like a lot of error messages for all the drivers. But the sqllite driver works and has the same messages as the MySQL driver so I wouldn't think that is an issue. However I do see at the end where It says it can't load qsqlmysqld.dll although I have confirmed that it is there and just before that it said it was loaded. I don't have a clue how to fix this even after reviewing a lot of information on this and other forums.

      What am I doing wrong?

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

        Hi,

        When you say that you added MySQL to the path environment variable, do you mean globally or in the run panel of your application ?

        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
        • G Offline
          G Offline
          gpuckett54
          wrote on last edited by
          #4

          I added it to the PATH environment variable. I checked the Run Environment for the project and verified that it picked up the latest changes to the environment variable in both the Build and Run configurations.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            gpuckett54
            wrote on last edited by
            #5

            I resolved the issue. I realized that since I had both the 64-bit and 32-bit versions of MySQL installed on my machine I had to have the 64-bit version in the path. That is what was causing the connection to fail in my code. I changed the path in the project configuration to point to the 32-bit version of MySQL and it worked great.

            I would rather be generating a 64-bit application but some of my 3rd party tools are only available in 32-bit so I am limited.

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

              That's the eternal struggle…

              When developing you should avoid modifying your system's PATH. Do it directly in the IDE. That way you ensure that you are not using accidentally the libraries of some third party application/framework.

              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

              • Login

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