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. Qt SQL doesn't detect any driver
Forum Updated to NodeBB v4.3 + New Features

Qt SQL doesn't detect any driver

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 1.5k Views 3 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.
  • J Offline
    J Offline
    jay1
    wrote on last edited by
    #3

    I am using the

    Qt Creator Version 4.11.1, Qt 5.14.1 (MSVC 2017, 32 bit) on windows
    

    I installed Qt using the Qt Installer and updated using the Maintainance.exe tool.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Hgi
      Ok, that should not be possible that it's not included. o.O
      Could you try to use it ?

      bool createConnection()
      {
          QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
          db.setDatabaseName(":memory:");
          //  db.setDatabaseName("c:\\folder\\test.db");
          if (!db.open()) {
              QMessageBox::critical(0, qApp->tr("Cannot open database"), "Click Cancel to exit.",
                                    QMessageBox::Cancel);
              return false;
          }
          QSqlQuery query;
          qDebug() << "table:" <<   query.exec("create table person (id int primary key, "
                                               "firstname varchar(20), lastname varchar(20), num int )");
          query.exec("insert into person (firstname , lastname, num) values('Dennis', 'Young','1')");
          query.exec("insert into person values(102, 'Christine', 'Holand','2')");
          query.exec("insert into person values(103, 'Lars junior', 'Gordon','4')");
          query.exec("insert into person values(104, 'Roberto', 'Robitaille','5')");
          query.exec("insert into person values(105, 'Maria', 'Papadopoulos','3')");
          return true;
      }
      
      J 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #5

        Hi,

        Is it the About Qt Creator dialog content ?
        If so, we need the version of Qt you are using in your kit.

        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
        1
        • J Offline
          J Offline
          jay1
          wrote on last edited by
          #6

          Yes it is from the Qt Creator about content.

          The version of the Qt from the kit I am using is

          Qt 5.14.0 MSVC2017 64bit
          

          for building my application

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

            Can you check the content of the sqldrivers folder in the plugins directory of that Qt version ?

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

            J 1 Reply Last reply
            1
            • mrjjM mrjj

              Hgi
              Ok, that should not be possible that it's not included. o.O
              Could you try to use it ?

              bool createConnection()
              {
                  QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
                  db.setDatabaseName(":memory:");
                  //  db.setDatabaseName("c:\\folder\\test.db");
                  if (!db.open()) {
                      QMessageBox::critical(0, qApp->tr("Cannot open database"), "Click Cancel to exit.",
                                            QMessageBox::Cancel);
                      return false;
                  }
                  QSqlQuery query;
                  qDebug() << "table:" <<   query.exec("create table person (id int primary key, "
                                                       "firstname varchar(20), lastname varchar(20), num int )");
                  query.exec("insert into person (firstname , lastname, num) values('Dennis', 'Young','1')");
                  query.exec("insert into person values(102, 'Christine', 'Holand','2')");
                  query.exec("insert into person values(103, 'Lars junior', 'Gordon','4')");
                  query.exec("insert into person values(104, 'Roberto', 'Robitaille','5')");
                  query.exec("insert into person values(105, 'Maria', 'Papadopoulos','3')");
                  return true;
              }
              
              J Offline
              J Offline
              jay1
              wrote on last edited by
              #8

              @mrjj I tried the code you provided with one change i.e. removed the QMessageBox and printed the qDebug() message. The code i tried is as follows followed with the output:

              #include <QDebug>
              #include <QSqlDatabase>
              #include <QMessageBox>
              #include <QSqlQuery>
              
              bool createConnection()
              {
                  QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
                  db.setDatabaseName(":memory:");
                  //  db.setDatabaseName("c:\\folder\\test.db");
                  if (!db.open()) {
                      qDebug() << "Failed to open the database";
                      return false;
                  }
                  QSqlQuery query;
                  qDebug() << "table:" <<   query.exec("create table person (id int primary key, "
                                                       "firstname varchar(20), lastname varchar(20), num int )");
                  query.exec("insert into person (firstname , lastname, num) values('Dennis', 'Young','1')");
                  query.exec("insert into person values(102, 'Christine', 'Holand','2')");
                  query.exec("insert into person values(103, 'Lars junior', 'Gordon','4')");
                  query.exec("insert into person values(104, 'Roberto', 'Robitaille','5')");
                  query.exec("insert into person values(105, 'Maria', 'Papadopoulos','3')");
                  return true;
              }
              
              int main(int argc, char *argv[])
              {
                  Q_UNUSED(argc)
                  Q_UNUSED(argv)
              
                  qDebug() << "List the drivers: " << QSqlDatabase::drivers();
              
                  createConnection();
              	return EXIT_SUCCESS;
              	
              }
              '''
              OUTPUT: 
              '''
              List the drivers:  ()
              QSqlDatabase: QSQLITE driver not loaded
              QSqlDatabase: available drivers: 
              QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins
              Failed to open the database
              

              I find this "QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins" statement kind of related as I had not created QCoreApplication in this scenario and also in my actual scenario there is not QCoreApplication whereI am using the QTest. But I think I must be able to create the QTest with sql drivers loaded , Please correct me if I am wrong?

              1 Reply Last reply
              0
              • SGaistS SGaist

                Can you check the content of the sqldrivers folder in the plugins directory of that Qt version ?

                J Offline
                J Offline
                jay1
                wrote on last edited by
                #9

                @SGaist In the Qt directory ```
                C:\Qt\5.14.0\msvc2017_64\plugins\sqldrivers

                I was able to find the files 
                1. qsqlite.dll
                2. qsqlodbc.dll
                3. qsqlpsql.dll
                
                and this
                
                1. qsqlited.dll
                2. qsqlodbcd.dll
                3. qsqlpsqld.dll
                
                

                And also I use "windeployqt" for deploying and have the "sqldrives" directory along with my executable which have the above dll sql files

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

                  Start your application with the QT_DEBUG_PLUGINS environment variable set to 1.

                  It should give you the reason of the failure.

                  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
                  1
                  • J Offline
                    J Offline
                    jay1
                    wrote on last edited by
                    #11

                    @SGaist I added the QT_DEBUG_PLUGINS = 1 to environment variables. And when I build I was not able to get any log information in Application output. But when I added the

                    QAppication a(argc, argv)
                    

                    I was able to see the log related to SQLITE Plugin metadata.

                    After the addition of the "QApplication a(argc, argv)" I was able to retrieve/get the list of drives SQL drivers

                    List the drivers:  ("QSQLITE", "QODBC", "QODBC3", "QPSQL", "QPSQL7")
                    

                    I think to load sql plugins we need the QCoreApplication to be triggered, need to digup more about about the plugins loading.

                    Thanks for providing the feedback and direction

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

                      Well, when using Qt, the first object you have to create is QCoreApplication or one of its subclass. It is needed in order to setup only the internals and plumbing needed for Qt to work.

                      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
                      2

                      • Login

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