Please nominate your Qt Champions for 2021!

QSqlDatabase open only existing database

  • How to prevent Qt from creating an empty database file (in case of SQLITE driver), when i'm using I want to show error and terminate application if it's root folder doesn't contain SQLite3 database file, else - open dbfile or show error if it is corrupted.

  • Lifetime Qt Champion

    its the default action of SQLite engine AFASIK.
    You can just check yourself if file is in place

    #include <QFileInfo>
    bool fileExists(QString path) {
        QFileInfo check_file(path);
        // check if file exists and if yes: Is it really a file and no directory?
        return check_file.exists() && check_file.isFile();

  • @mrjj
    Thanks for the clarifying, marking as solved.

Log in to reply