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> Qt Ubuntu SqLite driver not loaded
Forum Updated to NodeBB v4.3 + New Features

<SOLVED> Qt Ubuntu SqLite driver not loaded

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

    Hi everyone!
    Im running Qt Creator 2.8.1 based on Qt 5.1.1 (GCC 4.6.1, 64 bit) on Ubuntu.

    Im trying to make a simple application using SQLite, but i cant get the driver loading.

    On the .pro file I included QT += sql

    Then my code is as follows:

    @
    #include <QtSql>
    #include <QSqlDriver>
    #include <QMessageBox>

    QMessageBox Error;
    QSqlDatabase db;
    QSqlQuery Query(db);
    db= QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("example.db3");
    if(!db.open())
    {
    Error.setText("Couldnt open databse");
    Error.exec();
    }
    if(!db.isDriverAvailable("QSQLITE"))
    {
    Error.setText("Driver not available");
    Error.exec();
    }

    Query.prepare("CREATE TABLE t1 (t1key INTEGER PRIMARY KEY, data TEXT, num double, timeEnter Date)");
    if(!Query.exec())
    {
    SqlError=Query.lastError();
    Error.setText("Query error 001: "+SqlError.text());
    Error.exec();
    }

    @

    When I run this, I get the error "Query error 001: Driver not loaded Driver not loaded"
    Apparently the driver is available (the error "driver not available" doesnt show), and the database is opened, but i cant run any query.
    I checked, and the database example.db3 is created on my program directory, so SQLite is working...
    To get more information I added:

    @
    QStringList list=db.drivers();
    @
    And when I debug this, list contains
    "QSQLITE"
    "QMYSQL"
    "QMYSQL3"
    "QPSQL"
    "QPSQL7"
    So the driver is deffinitly there, but it cant be loaded.
    I read loads of forum posts with people having the same problem, but all of them were fixed when they moved into the program directory the sqldrivers folder. Im running my program from QT, and it doesnt work, so i guess that solution wont help me.
    Any ideas with what im doing wrong?

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

      Hi,

      Run ldd on your plugin to check whether it can find all the required libraries

      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
      • D Offline
        D Offline
        darkp03
        wrote on last edited by
        #3

        Im kind of new to Linux, but I searched the libqsqlite.so located at (/Qt5.1.1/Tools/QtCreator/bin/plugins/sqldrivers) and ran the ldd on it, this was the result

        nicolas@Ksi:~/Qt5.1.1/Tools/QtCreator/bin/plugins/sqldrivers$ ldd libqsqlite.so

        linux-vdso.so.1 => (0x00007fff585fe000)
        libQt5Sql.so.5 => /home/nicolas/Qt5.1.1/Tools/QtCreator/bin/plugins/sqldrivers/./../../../lib/qtcreator-/libQt5Sql.so.5 (0x00007fc5d6911000)
        libQt5Core.so.5 => /home/nicolas/Qt5.1.1/Tools/QtCreator/bin/plugins/sqldrivers/./../../../lib/qtcreator/libQt5Core.so.5 (0x00007fc5d6286000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc5d6057000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fc5d5d57000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc5d5997000)
        libicui18n.so.51 => /home/nicolas/Qt5.1.1/Tools/QtCreator/bin/plugins/sqldrivers/./../../../lib/qtcreator/./libicui18n.so.51 (0x00007fc5d557e000)
        libicuuc.so.51 => /home/nicolas/Qt5.1.1/Tools/QtCreator/bin/plugins/sqldrivers/./../../../lib/qtcreator/./libicuuc.so.51 (0x00007fc5d51f7000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc5d4ff3000)
        libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007fc5d4df1000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fc5d4be8000)
        libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fc5d48f3000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc5d45f7000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc5d43e0000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fc5d6e06000)
        libicudata.so.51 => /home/nicolas/Qt5.1.1/Tools/QtCreator/bin/plugins/sqldrivers/./../../../lib/qtcreator/././libicudata.so.51 (0x00007fc5d2c97000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fc5d2a59000)

        not sure what it means though, or if that was what i was supposed to do :S

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

          ldd search for all libraries that are linked to your library.

          The thing is that you have found the qsqlite plugin from Qt Creator which is not the one you are using right now. You have to search in the folder where you have the Qt libraries which IIRC is at the same level as the Tools folder

          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
          • D Offline
            D Offline
            darkp03
            wrote on last edited by
            #5

            After a long time, ive found the "error".
            I was really surprised, because theres no actual problem in my code, and the documentation never spoke about these. I was also surprised that more people didnt have my problem, maybe its a combination of my qt version and drivers, no idea, but this is what was happening.

            The query must be created in the line after opening the database. for example
            @
            QSqlDatabase db;
            db = QSqlDatabase::addDatabase("QSQLITE");
            QSqlQuery query();
            db.setDatabaseName("ejemplo.db3");
            unsigned int useless int;
            for(int i=0;i<255;i**)
            useless int ++;
            db.open();
            Query.prepare("CREATE TABLE t1 (t1key INTEGER PRIMARY KEY,data TEXT,num double,timeEnter DATE)");
            @
            WONT WORK, but if you do this instead

            @
            QSqlDatabase db;
            db = QSqlDatabase::addDatabase("QSQLITE");
            db.setDatabaseName("ejemplo.db3");
            unsigned int useless int;
            for(int i=0;i<255;i**)
            useless int ++;
            db.open();
            QSqlQuery query();
            Query.prepare("CREATE TABLE t1 (t1key INTEGER PRIMARY KEY,data TEXT,num double,timeEnter DATE)");
            @
            works like a charm

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

              Because you were doing it wrong (and not following the documentation examples)

              addDatabase only tells what kind of database you will be using, you don't have any valid connection right now. So creating the query at this point is the same as trying to write to a file without path that you have not opened yet.

              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