QSqlDatabase open only existing database



  • How to prevent Qt from creating an empty database file (in case of SQLITE driver), when i'm using db.open()? 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.


  • Qt Champions 2016

    Hi
    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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.