Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QSqlDatabase: QMYSQL driver not loaded

    General and Desktop
    3
    3
    976
    Loading More Posts
    • 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
      matobodo last edited by

      I have MYSQL database. When I try to execute a query i get this error:
      QSqlDatabase: QMYSQL driver not loaded
      QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

      How can I solve it?

      Code:
      main.cpp
      @#include <QCoreApplication>
      #include <QDebug>
      #include <QtSql>

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

      QString driver = "QMYSQL";
      
      QSqlDatabase db;
      db = QSqlDatabase::addDatabase(driver,dbName);
      db.setHostName(hostName);
      db.setPort(port);
      db.setDatabaseName(dbName);
      db.setUserName(userName);
      db.setPassword(password);
      
      if (db.open()) {
          qDebug() << "Opened!";
          QSqlQuery *qry = new QSqlQuery(db);
          if (qry->exec&#40;"SELECT * FROM `cechosped_users`"&#41;) {
              qDebug() << "Executed!";
          } else {
              qDebug() << "Error:";
              qDebug() << qry->lastError().text();
          }
      } else {
          qDebug() << "Error:";
          qDebug() << db.lastError().text();
      }
      
      return a.exec&#40;&#41;;
      

      }
      @

      1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators last edited by

        Hi,

        There are lots of posts related to this problem in this forum. Have a look at those.

        157

        1 Reply Last reply Reply Quote 0
        • K
          kiwing last edited by

          check another forum like this one
          http://qt-project.org/forums/viewthread/36482 and
          http://qt-project.org/forums/viewthread/36656

          the key is never tired to read !
          ok brother ?!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post