[Solved] SQLite not working ("driver not loaded") in deployed application, regular solutions aren't working



  • Hi everyone,

    I'm working within a large application with many developers, but I'm the only one using SQLite, and I've been learning as I go and only have Google to turn to for solutions when I run into problems. I'll try to include all the details, but if I miss anything, please let me know and I'll do my best to provide it.

    First off, I'm using Visual Studio 2010 on a Windows 7 machine, and am currently using Qt 4.8.1.

    Everything works fine in debug mode, and release mode, as long as I'm running the executables that VS2010 has built. But when the software is built into our deployed package, suddenly I'm getting that dreaded "Driver not loaded Driver not loaded".

    I've Googled this for days, and I've tried the following:

    • putting qsqlite4.dll in a directory named "sqldrivers" in the directory where the executable is (doesn't work)

    • putting qsqlite4.dll in plugins/sqldrivers (where plugins is in the same directory as the executable)

    • I have

    @Qt += SQL@

    in all the necessary .pro files

    One thing I did notice is that the files qsqlite4.dll and QtSql4.dll that were in our deployed version were not the same files as the qsqlite4.dll and QtSql4.dll files I had in my Qt 4.8.1 folder. So I tried copying those files in to overwrite the files in the deployed package, but that didn't do the trick either. But it leads me to believe that it's something to do with how we're building the deployed version. Could I be on to something here?

    I have this call when my Sql-managing class is built:

    @m_database = QSqlDatabase::addDatabase("QSQLITE");@

    And I open it like so:

    @
    if (m_database.isValid())
    {
    m_database.setDatabaseName(databasePath);
    }
    @

    Of course, the call to

    @isValid()@

    is failing for me, because the driver wasn't loaded.

    I don't have anything to do with the process of building our deployed version of the program, so maybe there's some questions I can ask the person who is doing that?

    It also may be worth noting that the application is accessing database files that exist outside the scope of the application directory. (Users open projects that exist in various places on their local disk, and each project holds a Sqlite database.)

    If anyone has any ideas, I'll be eternally grateful. This has been driving me bonkers.

    Cheers!


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    For deployment problem you should first (or the person in charge) use the "windows deployment guide":https://qt-project.org/doc/qt-4.8/deployment-windows.html

    Be aware that you cannot mix newer and older plugins, they have to match the Qt libraries that are in your installer. Also the folders are important.



  • Wow, okay, so I figured out the problem and I feel like a moron.

    Before today, I would have sworn up and down that the database was being initialized after the QApplication had finished initializing. No idea how it took me this long to realize, but I was wrong.

    After moving this

    @
    m_database = QSqlDatabase::addDatabase("QSQLITE");
    @

    To a portion of the code that runs after the QApplication has finished initializing, everything works fine.

    Now let's see if my newbie self can figure out how to mark this as solved...


  • Lifetime Qt Champion

    Glad you found out !

    Qt rule number one: first thing to do is create a QCoreApplication/QGuiApplication/QApplication (depending on your type of application)

    It does all the initialization Qt needs to function properly.

    Happy coding ! :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.