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. QSqlite driver does not load
Forum Update on Monday, May 27th 2025

QSqlite driver does not load

Scheduled Pinned Locked Moved General and Desktop
sqldesktopdllqsqldatabasedriversqliteplugindeployment
20 Posts 4 Posters 18.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.
  • T Offline
    T Offline
    Tuby1
    wrote on 30 Jun 2015, 17:33 last edited by
    #1

    Hello,

    I'm having hard time trying to launch my application correctly on win7 64b,
    I created app that uses sqlite3 as database, everything works fine in creator, app works its best.
    Unfortunately when I'm trying to launch app outside the creator it fails to load sql driver.
    What I did was, copied .exe from qt release folder, opened dependencywalker and threw bunch of dll's inside.
    Thats how my folder looks like:

    • .exe
    • (required dlls from dependencywalker, guess I don't have to mention them)
    • icudt53,icuin53,icuuc53
    • libEGL
    • libgcc_s_dw2-1
    • libwinpthread-1
      Folder sqldrivers:
    • qsqlite
    • libsqlite3-0
      Folder platforms
    • qwindows

    db is my QSqlDatabase object and its private object of mainwindow class.
    Here where it gets messy, its mainwindow ctor.

    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("data.db");
    

    and at this point it should've created new database called data.db if it doesn't already exists, in creator it does so I expect same results outside also.
    Unfortunately it pops error "Driver not loaded", you could say there is no dll for the driver, the fun part is that QSqlDatabase::drivers pops that there is 1 available driver "QSQLITE" so why it doesn't load, could someone explain it to me, please?
    Talk to me like to a total newbie, I didn't read any qt tutorials/books, just figuring things out by myself. If there is fancy magic why it doesn't work please be very precise with explanation.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Leonardo
      wrote on 30 Jun 2015, 17:52 last edited by
      #2

      Try using the windows deployment tool. It's a great start point.

      http://doc.qt.io/qt-5/windows-deployment.html#the-windows-deployment-tool

      1 Reply Last reply
      0
      • D Offline
        D Offline
        danks_
        wrote on 10 Jul 2015, 20:41 last edited by danks_ 7 Oct 2015, 20:52
        #3

        I'm having the same problem... Whenever I try to open a database it just ends up like this:
        QSqlDatabase(driver="QSQLITE", database="", host="", port=-1, user="", open=true) true

        This means that everytime I try to use QSqlQuery, I get the following error(s):
        QSqlQuery::prepare: database not open
        QSqlError("", "Driver not loaded", "Driver not loaded")

        This is how my connection looks like:

         static bool createConnection(QString dbName) {
            QSqlDatabase dbLotto = QSqlDatabase::addDatabase("QSQLITE", dbName);
            dbLotto.open();
            qDebug()<< dbLotto <<dbLotto.isOpen();
            if (!dbLotto.open()) {
                return false;
            } else {
                return true; 
            }
        }
        

        and it's being called like so:

        if(!createConnection("C:\\LottoNCA\\SZ10.sqlite")){
            ...
        }
        

        Error persists even is I set it to be C:/LottoNCA/SZ10.sqlite. Just like OP mentioned, if the file doesn't exist, it should create one at the very least. The file gets created, but it doesn't connect to it?

        Edit: When using db.setDatabaseName (File Path); the following occurs

        error: 'class QSqlDatabase' has no member named 'setDatabaseName'
        
        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 10 Jul 2015, 20:52 last edited by mrjj 7 Oct 2015, 20:53
          #4

          I had the same issue too, i made mine work by

          create a folder in my deploy folder
          called "sqldrivers"
          with these files in it
          qsqlite.dll
          qsqlited.dll

          and also
          Qt5Sqld.dll
          in the root of the deploy folder. (where my exe is)

          Directory of F:\dropbox\Time\Klok\Tools
          05-05-2015 15:05 <DIR> sqldrivers<-------------------------
          09-12-2014 20:21 10.397.296 icudt52.dll
          14-09-2014 03:28 1.798.656 icuin52.dll
          14-09-2014 03:28 1.304.064 icuuc52.dll
          07-03-2014 20:56 117.262 libgcc_s_dw2-1.dll
          07-03-2014 20:56 970.766 libstdc++-6.dll
          07-03-2014 20:56 48.640 libwinpthread-1.dll
          10-03-2015 13:52 1.449.613 mpreader.exe
          20-10-2014 08:55 77.428.646 Qt5Cored.dll
          11-09-2014 15:36 5.156.192 Qt5Sqld.dll<-----------------------

          I got the same error "not loaded" running prepare so I hope it solves yours too.

          1 Reply Last reply
          2
          • L Offline
            L Offline
            Leonardo
            wrote on 10 Jul 2015, 20:55 last edited by
            #5

            "qsqlited" and "Qt5Sqld" are only required when building in debug mode. That's what the "d" stands for. When building in release mode, you should use "qsqlite" and "Qt5Sql".

            M 1 Reply Last reply 10 Jul 2015, 21:04
            1
            • L Leonardo
              10 Jul 2015, 20:55

              "qsqlited" and "Qt5Sqld" are only required when building in debug mode. That's what the "d" stands for. When building in release mode, you should use "qsqlite" and "Qt5Sql".

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 10 Jul 2015, 21:04 last edited by
              #6

              @Leonardo
              Yes, should be the -d version. thank you for catching. i used the folder to test standalone also even in debug builds.

              After reading OPs post more carefully , it seems the only difference is
              Qt5Sql.dll vs libsqlite3-0

              D 1 Reply Last reply 10 Jul 2015, 21:07
              1
              • M mrjj
                10 Jul 2015, 21:04

                @Leonardo
                Yes, should be the -d version. thank you for catching. i used the folder to test standalone also even in debug builds.

                After reading OPs post more carefully , it seems the only difference is
                Qt5Sql.dll vs libsqlite3-0

                D Offline
                D Offline
                danks_
                wrote on 10 Jul 2015, 21:07 last edited by
                #7

                @mrjj I'm running it from inside QT, the file is located here:
                Documents\build-LNCA-Desktop_Qt_5_5_0_MinGW_32bit-Debug\debug

                So I created the folder
                Documents\build-LNCA-Desktop_Qt_5_5_0_MinGW_32bit-Debug\debug\sqldrivers

                and added qsqlite.dll (and d.dll), and added Qt5Sql.dll (and d.dll), error persists,.

                M 1 Reply Last reply 10 Jul 2015, 21:17
                0
                • D danks_
                  10 Jul 2015, 21:07

                  @mrjj I'm running it from inside QT, the file is located here:
                  Documents\build-LNCA-Desktop_Qt_5_5_0_MinGW_32bit-Debug\debug

                  So I created the folder
                  Documents\build-LNCA-Desktop_Qt_5_5_0_MinGW_32bit-Debug\debug\sqldrivers

                  and added qsqlite.dll (and d.dll), and added Qt5Sql.dll (and d.dll), error persists,.

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 10 Jul 2015, 21:17 last edited by
                  #8

                  @danks_
                  Damn, so even it sounded the same, the fix was not. You seems to copy files to correct/same place.

                  Well, then I think Leonardos suggestion is pretty good, try to use the deployment tool and see if
                  copy some extra dlls.

                  D 1 Reply Last reply 10 Jul 2015, 21:24
                  1
                  • M mrjj
                    10 Jul 2015, 21:17

                    @danks_
                    Damn, so even it sounded the same, the fix was not. You seems to copy files to correct/same place.

                    Well, then I think Leonardos suggestion is pretty good, try to use the deployment tool and see if
                    copy some extra dlls.

                    D Offline
                    D Offline
                    danks_
                    wrote on 10 Jul 2015, 21:24 last edited by
                    #9

                    @mrjj
                    I moved all the files and used Release this time, instead of debug

                    Running from C:\LottoNCA\LNCA\Release\release
                    all needed .dlls are there (sqldrivers folder present as well)

                    Error persists :c

                    M 1 Reply Last reply 10 Jul 2015, 21:29
                    0
                    • D danks_
                      10 Jul 2015, 21:24

                      @mrjj
                      I moved all the files and used Release this time, instead of debug

                      Running from C:\LottoNCA\LNCA\Release\release
                      all needed .dlls are there (sqldrivers folder present as well)

                      Error persists :c

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 10 Jul 2015, 21:29 last edited by
                      #10

                      @danks_
                      :(
                      if you
                      qDebug() << QSqlDatabase::drivers();

                      it does list sqlite?

                      D 1 Reply Last reply 10 Jul 2015, 21:41
                      1
                      • M mrjj
                        10 Jul 2015, 21:29

                        @danks_
                        :(
                        if you
                        qDebug() << QSqlDatabase::drivers();

                        it does list sqlite?

                        D Offline
                        D Offline
                        danks_
                        wrote on 10 Jul 2015, 21:41 last edited by
                        #11

                        @mrjj
                        ("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7") is what I see, but I guess it's because I'm running from inside Qt

                        M 1 Reply Last reply 10 Jul 2015, 21:44
                        0
                        • D danks_
                          10 Jul 2015, 21:41

                          @mrjj
                          ("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7") is what I see, but I guess it's because I'm running from inside Qt

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 10 Jul 2015, 21:44 last edited by mrjj 7 Oct 2015, 21:49
                          #12

                          @danks_ do you get same list from if you run it standalone ?
                          I get only "QSQLITE" as expected.

                          D 1 Reply Last reply 10 Jul 2015, 21:53
                          1
                          • M mrjj
                            10 Jul 2015, 21:44

                            @danks_ do you get same list from if you run it standalone ?
                            I get only "QSQLITE" as expected.

                            D Offline
                            D Offline
                            danks_
                            wrote on 10 Jul 2015, 21:53 last edited by
                            #13

                            @mrjj Weirdly, I do get the same list from standalone...

                            I wasn't sure about how to get the list from standalone, since standalone doesn't show qDebug, so I did the following:

                             QStringList testStr;
                             testStr << QSqlDatabase::drivers();
                             QString str = testStr.join("");
                             str = testStr.join(",");
                             QMessageBox boxQry;
                                        boxQry.setText(str);
                                        boxQry.exec();
                            

                            Standalone folder only has sqlite.dll inside of sqldrivers folder, I'm really confused now.

                            M 1 Reply Last reply 10 Jul 2015, 22:06
                            0
                            • D danks_
                              10 Jul 2015, 21:53

                              @mrjj Weirdly, I do get the same list from standalone...

                              I wasn't sure about how to get the list from standalone, since standalone doesn't show qDebug, so I did the following:

                               QStringList testStr;
                               testStr << QSqlDatabase::drivers();
                               QString str = testStr.join("");
                               str = testStr.join(",");
                               QMessageBox boxQry;
                                          boxQry.setText(str);
                                          boxQry.exec();
                              

                              Standalone folder only has sqlite.dll inside of sqldrivers folder, I'm really confused now.

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 10 Jul 2015, 22:06 last edited by
                              #14

                              @danks_
                              oh so it list all drivers even it should only see the lite one.
                              That is not what I would expect.

                              I also checked in release build and still only got QSQLITE.

                              Also I wonder a bit about
                              db.setDatabaseName (File Path); error as I use that call.

                              db = QSqlDatabase::addDatabase ( "QSQLITE" );
                                  db.setDatabaseName ( DBPath );        
                                  if ( db.open() )  ...
                              

                              Also Im using qt 5.4 so I wonder if setDatabaseName was dropped.

                              D 1 Reply Last reply 10 Jul 2015, 22:12
                              1
                              • M mrjj
                                10 Jul 2015, 22:06

                                @danks_
                                oh so it list all drivers even it should only see the lite one.
                                That is not what I would expect.

                                I also checked in release build and still only got QSQLITE.

                                Also I wonder a bit about
                                db.setDatabaseName (File Path); error as I use that call.

                                db = QSqlDatabase::addDatabase ( "QSQLITE" );
                                    db.setDatabaseName ( DBPath );        
                                    if ( db.open() )  ...
                                

                                Also Im using qt 5.4 so I wonder if setDatabaseName was dropped.

                                D Offline
                                D Offline
                                danks_
                                wrote on 10 Jul 2015, 22:12 last edited by
                                #15

                                @mrjj
                                Maybe I should go to 5.4 and try my luck :)
                                I guess I'll let you know, thanks a lot for your help!

                                M 1 Reply Last reply 10 Jul 2015, 22:22
                                0
                                • D danks_
                                  10 Jul 2015, 22:12

                                  @mrjj
                                  Maybe I should go to 5.4 and try my luck :)
                                  I guess I'll let you know, thanks a lot for your help!

                                  M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 10 Jul 2015, 22:22 last edited by
                                  #16

                                  @danks_
                                  Well, there is no reason it should not work in 5_5. but could be fun to test 5.4 just to see.
                                  tomorrow I will try 5_5 in virtual machine. I was planning to upgrade :)

                                  You are most welcome. Sadly we did not find a fix.

                                  D 1 Reply Last reply 10 Jul 2015, 22:25
                                  0
                                  • M mrjj
                                    10 Jul 2015, 22:22

                                    @danks_
                                    Well, there is no reason it should not work in 5_5. but could be fun to test 5.4 just to see.
                                    tomorrow I will try 5_5 in virtual machine. I was planning to upgrade :)

                                    You are most welcome. Sadly we did not find a fix.

                                    D Offline
                                    D Offline
                                    danks_
                                    wrote on 10 Jul 2015, 22:25 last edited by
                                    #17

                                    @mrjj It's all about learning, maybe someone will post a solution sometime :) if 5.4 gets it done, there's no real downside for me haha

                                    M 1 Reply Last reply 10 Jul 2015, 22:56
                                    0
                                    • D danks_
                                      10 Jul 2015, 22:25

                                      @mrjj It's all about learning, maybe someone will post a solution sometime :) if 5.4 gets it done, there's no real downside for me haha

                                      M Offline
                                      M Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on 10 Jul 2015, 22:56 last edited by
                                      #18

                                      @danks_
                                      Absolutely. Yeah if we are lucky someone will show us the light tomorrow :)
                                      I have this feeling it is something very simple.

                                      D 1 Reply Last reply 11 Jul 2015, 00:20
                                      1
                                      • M mrjj
                                        10 Jul 2015, 22:56

                                        @danks_
                                        Absolutely. Yeah if we are lucky someone will show us the light tomorrow :)
                                        I have this feeling it is something very simple.

                                        D Offline
                                        D Offline
                                        danks_
                                        wrote on 11 Jul 2015, 00:20 last edited by
                                        #19

                                        @mrjj 5.4 worked flawlessly, maybe a bug to be reported? :p

                                        M 1 Reply Last reply 11 Jul 2015, 08:39
                                        0
                                        • D danks_
                                          11 Jul 2015, 00:20

                                          @mrjj 5.4 worked flawlessly, maybe a bug to be reported? :p

                                          M Offline
                                          M Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on 11 Jul 2015, 08:39 last edited by mrjj 7 Nov 2015, 10:04
                                          #20

                                          @danks_
                                          That is good to hear !
                                          Could also been some kind of setup problem with 5_5 but yeah it does
                                          seems like a bug.

                                          I will try with 5_5 and see it it fails for me too.

                                          update:
                                          Tested win pure 5_5 install
                                          It worked by copying the DLLs ! ?
                                          Even worked with no sub sqldrivers folder ...!
                                          (in the release folder)

                                          But when moved out of the virtual machines
                                          it did want the sqldrivers folder to work.

                                          So the current version of 5.5 via the online installer does seems to work in regards to sql.?!

                                          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