Important: Please read the Qt Code of Conduct -

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