QSQLITE driver not loaded



  • Hi!
    I have problem with deployed application. It could not create and access sqlite database, with next messages in debugger:

    QSqlDatabase: QSQLITE driver not loaded
    QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
    bool AnisStorage::setupDb() Error: "Driver not loaded Driver not loaded"
    QSqlQuery::exec: database not open
    

    And here is code example:

        m_dbConnection = QSqlDatabase::addDatabase("QSQLITE");
        // m_dbName = D:/QtBuilds/kvant-cpm-release/cpmStorage.sqlite
        m_dbConnection.setDatabaseName(m_dbName); 
        const bool isDbOpened = m_dbConnection.open();
    
        if(!isDbOpened) {
            qDebug() << Q_FUNC_INFO << "Error:" << m_dbConnection.lastError().text();
            return false;
        }
    

    I am using Qt 5.4.2, MinGW 4.9.2 and have "sqldrivers" dir with Qt SQL drivers in application folder.

    How to fix this?)



  • Hello

    I have the same problem. I use Qt 5.5 on Archlinux.

    This my codes:
    storage.h:

    #ifndef STORAGE_H
    #define STORAGE_H
    
    #include <QObject>
    #include <QSqlDatabase>
    #include <QDebug>
    #include <QSqlError>
    #include <QSqlDriver>
    
    class QString;
    
    
    
    class Storage : public QObject
    {
        Q_OBJECT
    public:
        explicit Storage(QObject *parent = 0);
        Q_INVOKABLE bool open();
    
    signals:
    
    public slots:
    
    private:
        QSqlDatabase* m_sqlDatabase;
    
    };
    
    #endif // STORAGE_H
    

    storage.cpp:

    #include "storage.h"
    
    Storage::Storage(QObject *parent) : QObject(parent)
    {
        m_sqlDatabase = new QSqlDatabase();
    
    }
    
    bool Storage::open()
    {
    
        qDebug() << QSqlDatabase::drivers();
        qDebug() << QSqlDatabase::isDriverAvailable("QSQLITE3");
        m_sqlDatabase->addDatabase("QSQLITE3", "SQLITE");
        m_sqlDatabase->setDatabaseName("myBdd");
    
        if (m_sqlDatabase->open()){
            return true;
        }
    
        else{
            qDebug() << m_sqlDatabase->lastError();
            return false;
        }
    }
    

    and my .pro

    unix:LIBS += -lpq -L"/usr/lib/qt/plugins/sqldrivers"
    

    As ExorcistInc, I have this messages with qDebug() :
    ("QIBASE", "QSQLITE", "QSQLITE3", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3", "QPSQL", "QPSQL7")
    true
    QSqlError("", "Driver not loaded", "Driver not loaded")

    Have I include other file ?

    Thank you in advance

    Charlie



  • Well, I figured out, that in my case it was stupid mistake of using MSVC windeployqt with MinGW compiled app.


Log in to reply