Driver Not Loaded SQLITE

  • It has been more than a year that i have not use QT. My old computer died so i have a fresh installation of QT. I was refreshing my programming memory and tried to create a database with sqlite, but when i tried to run i get the error "Driver not loaded". I remember having the same problem a couple of years ago but cannot remember how to solve.

    QSqlDatabase myDatabase;
        qDebug() << "Here";
        qDebug() << QSqlDatabase::drivers();
            qDebug() << "Error";
            qDebug()<< myDatabase.lastError();
    QSqlError("", "Driver not loaded", "Driver not loaded")

  • I think you are using myDatabase.database("QSQLITE") wrongly.
    From documentation:

    [static] QSqlDatabase QSqlDatabase::database(const QString &connectionName = QLatin1String( defaultConnection ), bool open = true)
    Returns the database connection called connectionName. The database connection must have been previously added with addDatabase(). If open is true (the default) and the database connection is not already open it is opened now. If no connectionName is specified the default connection is used. If connectionName does not exist in the list of databases, an invalid connection is returned.

    The other things you can check are:

    • Do you have something like this in *.pro file:
    QT += sql
    • If your project is compiled in Release mode, do you have plugin in your application folder: sqldrivers/qsqlite.dll (this is for Windows).

  • You are correct, i was using database wrong. It pays to put attention to the documentation.

    myDatabase = QSqlDatabase::addDatabase("SQLITE");


  • @Dan3460
    In addDatabase() must be specified SQL driver and for SQLite it is "QSQLITE", not "SQLITE".

Log in to reply