From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.

how to connect to sqlite database

  • i want to connect to sqlite database
    this is my code:

    QSqlDatabase Database;
        if (!
            qDebug() << Database.lastError().text();

    but return me "Driver not loaded Driver not loaded"

    I copy qsqlite.dll in sqldrivers folder inside my app folder but don't work

  • Moderators

    @ARASHz4 That dll should be inside sqldrivers directory.
    Have a look at this wiki page.

  • This post is deleted!

  • You need to assign the connection like this:

    QSqlDatabase Database;
    Database = QSqlDatabase::addDatabase("QSQLITE");
    if (!
        qDebug() << Database.lastError().text();

  • about how to connect to sqlite database, what's the best form to do the connection?, once tiem at start and only get connexion or connect and close on each query.
    and is possible do update with bindvalue?

    thank you, sorry for my english!

  • Lifetime Qt Champion

    Often best design is open once at start.
    and close at end.

    • and is possible do update with bindvalue?

    yes. it is.

    QSqlQuery query;
    query.prepare("INSERT INTO person (id, forename, surname) "
                  "VALUES (:id, :forename, :surname)");
    query.bindValue(":id", 1001);
    query.bindValue(":forename", "Bart");
    query.bindValue(":surname", "Simpson");

Log in to reply