dimanche 8 mai 2016

QT QSqlDatabase open() function creates a sqlite database

I'm trying to open a sqlite database file in QT using .open() function and if the file doesn't exit, .open() doesn't return a false, it just creates a new file in the given directory. My code:

QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("C:/sqlite/newDB.db");

    if(!db.open()){
        ui->test->setText("Fail");
    }
    else{
        ui->test->setText("Success");
    }

How to make it return a true or false ?

Aucun commentaire:

Enregistrer un commentaire