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. QSqlDatabase: QSQLITE driver not loaded [SOLVED]

QSqlDatabase: QSQLITE driver not loaded [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
17 Posts 5 Posters 23.9k Views
  • 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.
  • K Offline
    K Offline
    kasun.chamara
    wrote on last edited by
    #1

    I'm creating app that connects to sqlite db
    here is the error getting when build & run

    @
    QSqlDatabase: QSQLITE driver not loaded
    QSqlDatabase: available drivers:
    @

    here is the code

    @
    QSqlDatabase mydb;
    void connClose(){
    mydb.close();
    }
    bool connOpen(){
    mydb = QSqlDatabase::addDatabase("QSQLITE");
    mydb.setDatabaseName("/home/ubuntu/test/newdb");
    if (!mydb.open()){
    qDebug()<<("Not Conected");
    return false;
    }
    else{
    qDebug()<<("DB Conected");
    return true;
    }
    }
    @

    @
    connOpen();
    if(mydb.isOpen()){
    ui->label_3->setText("Connected!");
    }else{
    ui->label_3->setText("Connection Fail!");
    }
    @

    files in sqldrivers directory
    @
    ubuntu@ubuntu:/usr/local/qt/plugins/sqldrivers$ ls
    libqsqlite.a libqsqlite.prl
    @

    Other Details:
    @Qt 4.8.6
    QtCreator 2.4.1
    armv7
    lubuntu@

    how to solve this problem. thanks!!

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      You are missing the libraries SQLite on your box. Ensure that all the required libraries for libraries are in path. Sometime some due to version mismatch in the library also you will get this error. There are many posts like "here":http://qt-project.org/forums/viewthread/36656 [qt-project.org]. They will surely solve your problem.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

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

        Hi,

        Looks like you are using a static build, did you properly import the sqlite plugin ?

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

          Hello,

          Have you try to open database in the main class?

          In the my project with Android if I don't open and close the database in main class then I can't open the db in another class, but the driver of sqlite exists.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kasun.chamara
            wrote on last edited by
            #5

            can you please guide me to

            • generate missing the libraries
            • import the sqlite plugin

            my downloaded qt 4.8.6 source is here:
            (qt-everywhere-opensource-src-4.8.6.tar.gz)
            @/home/ubuntu/Downloads/qt-src@

            statically built Qt resides here :
            @/usr/local/qt@

            @
            ubuntu@ubuntu:~$ dpkg -l | grep sqlite
            ii libqt4-sql-sqlite 4:4.8.1-0ubuntu4.8 Qt 4 SQLite 3 database driver
            ii libsqlite3-0 3.7.9-2ubuntu1.1 SQLite 3 shared library
            ii libsqlite3-dev 3.7.9-2ubuntu1.1 SQLite 3 development files
            ii sqlite3 3.7.9-2ubuntu1.1 Command line interface for SQLite 3
            @

            -thanks

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

              There's no missing libraries, you have built Qt statically so the plugin is also built statically.

              Search for Q_IMPORT_PLUGIN in the documentation for more information about the static use of a Qt plugin.

              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
              • K Offline
                K Offline
                kasun.chamara
                wrote on last edited by
                #7

                thanks for suggessions...
                i've add the lines .pro file but getting the same error
                @QT += core gui sql
                LIBS += -L"/usr/local/qt/plugins/sqldrivers" -lqsqlite
                QTPLUGIN += qsqlite@

                my /usr/local/qt/plugins/sqldrivers directory only contains libqsqlite.a libqsqlite.prl files
                dosen't it require any other files?

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

                  What about Q_IMPORT_PLUGIN in your code ?

                  No it doesn't, libqsqlite.a is the library containing the plugin

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

                  A 1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kasun.chamara
                    wrote on last edited by
                    #9

                    thanks lot...

                    @Q_IMPORT_PLUGIN(qsqlite)@
                    done the job...

                    just for get known
                    i've already installed sqlite3 libsqlite3-dev
                    does it help qt to works or Qt handle sqlite it self?

                    why is my self installed (general way) Qt5.3 sqldrivers directory contains more file then above i posted?

                    thank you again for great help...

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

                      Depends on how you configured Qt. Qt comes with it's own version of sqlite and IIRC when building your own version you have to tell configure to use the system's available sqlite if you don't want to use Qt's version.

                      Because you didn't install all related dev packages so to the auto detection failed for the other drivers and thus you only have the sqlite plugin.

                      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
                      • K Offline
                        K Offline
                        kasun.chamara
                        wrote on last edited by
                        #11

                        got it
                        thank you

                        1 Reply Last reply
                        0
                        • SGaistS SGaist

                          What about Q_IMPORT_PLUGIN in your code ?

                          No it doesn't, libqsqlite.a is the library containing the plugin

                          A Offline
                          A Offline
                          Avtansh Sharma
                          wrote on last edited by
                          #12
                          This post is deleted!
                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            Avtansh Sharma
                            wrote on last edited by
                            #13

                            @SGaist
                            Q_IMPORT_PLUGIN(qsqlite)
                            /home/user/Downloads/splinechart/main.cpp:41: error: undefined reference to 'qt_static_plugin_qsqlite()'

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

                              @Avtansh-Sharma : ?

                              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
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                Do you have a static build of Qt ?

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

                                A 1 Reply Last reply
                                0
                                • SGaistS SGaist

                                  Do you have a static build of Qt ?

                                  A Offline
                                  A Offline
                                  Avtansh Sharma
                                  wrote on last edited by
                                  #16

                                  @SGaist No but I want to use sqlite driver in my android app. The application works fine as desktop application on ubuntu

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

                                    Then why are you using the instructions for static plugins ? The SQLite plugin is not statically built.

                                    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