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. SQL on MAC
Forum Updated to NodeBB v4.3 + New Features

SQL on MAC

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 936 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.
  • L Offline
    L Offline
    LeoChen
    wrote on last edited by
    #1

    I try to use sql with Qt, however, my code get the following errors:

    Available drivers:
    "QSQLITE"
    "QMYSQL"
    "QMYSQL3"
    "QODBC"
    "QODBC3"
    "QPSQL"
    "QPSQL7"
    QSqlDatabase: QMYSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
    

    Here is my original code:

    #include <QCoreApplication>
    #include <QSqlDatabase>
    #include <QDebug>
    #include <QStringList>
    #include <QSqlQuery>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        //List all available databases
        qDebug() << "Available drivers:";
        QStringList drivers = QSqlDatabase::drivers();
        for(auto t_s: drivers) {
            qDebug() << t_s;
        }
    
    
        // open mySql
        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
        db.setHostName("localhost");
        db.setDatabaseName("mydata");
        db.setUserName("root");
        db.setPassword("");
        if(!db.open()) {
            qDebug() << "Failed to connect to root mysql admin";
        } else {
            qDebug() << "open";
        }
    
        QSqlQuery query(db);
        //varchar should has lenth
        query.exec("create table student(id int primary key, name varchar(20))");
    
        query.exec("insert into student values(1,'xiaogang')");
        query.exec("insert into student values(2,'xiaoming')");
        query.exec("insert into student values(3,'xiaohong')");
    
        query.exec("select id, name from student where id >= 2");
    
        while(query.next()) {
            int value0 = query.value(0).toInt();
            QString value1 = query.value(1).toString();
            qDebug() << value0 << value1;
        }
    
        return a.exec();
    }
    

    Did I miss something? thank you!

    jsulmJ 1 Reply Last reply
    0
    • L LeoChen

      I try to use sql with Qt, however, my code get the following errors:

      Available drivers:
      "QSQLITE"
      "QMYSQL"
      "QMYSQL3"
      "QODBC"
      "QODBC3"
      "QPSQL"
      "QPSQL7"
      QSqlDatabase: QMYSQL driver not loaded
      QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
      

      Here is my original code:

      #include <QCoreApplication>
      #include <QSqlDatabase>
      #include <QDebug>
      #include <QStringList>
      #include <QSqlQuery>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          //List all available databases
          qDebug() << "Available drivers:";
          QStringList drivers = QSqlDatabase::drivers();
          for(auto t_s: drivers) {
              qDebug() << t_s;
          }
      
      
          // open mySql
          QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
          db.setHostName("localhost");
          db.setDatabaseName("mydata");
          db.setUserName("root");
          db.setPassword("");
          if(!db.open()) {
              qDebug() << "Failed to connect to root mysql admin";
          } else {
              qDebug() << "open";
          }
      
          QSqlQuery query(db);
          //varchar should has lenth
          query.exec("create table student(id int primary key, name varchar(20))");
      
          query.exec("insert into student values(1,'xiaogang')");
          query.exec("insert into student values(2,'xiaoming')");
          query.exec("insert into student values(3,'xiaohong')");
      
          query.exec("select id, name from student where id >= 2");
      
          while(query.next()) {
              int value0 = query.value(0).toInt();
              QString value1 = query.value(1).toString();
              qDebug() << value0 << value1;
          }
      
          return a.exec();
      }
      

      Did I miss something? thank you!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @LeoChen Set QT_DEBUG_PLUGINS=1 environment variable and start your app. You should then see why the plug-in was not loaded (probably MySQL client library isn't available).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Hi,

        • Which version of MySQL are you using ?
        • Where is it installed ?

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

        L 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          • Which version of MySQL are you using ?
          • Where is it installed ?
          L Offline
          L Offline
          LeoChen
          wrote on last edited by
          #4

          @SGaist

          Chens-MacBook-Pro:2017-03-31 chen$ mysql --version
          mysql  Ver 14.14 Distrib 5.7.17, for osx10.12 (x86_64) using  EditLine wrapper
          Chens-MacBook-Pro:2017-03-31 chen$ which mysql
          /usr/local/bin/mysql
          
          
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Ok, then the plugin can't find its dependencies.

            You can use install_name_tool on it to point it to your MySQL installation or rebuild the plugin following the doc recommendations.

            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