hi,
i am working with a code like this ...
tr("Path to DB"), qApp->applicationDirPath(), "SQLite (*.sqlite3)");
if(!path.isEmpty()){
db.setDatabaseName(path);
if(!db.open()){
QMessageBox::critical(this, tr
("Error"), tr
("DB Error"));
}
QString path = QFileDialog::getOpenFileName(this,
tr("Path to DB"), qApp->applicationDirPath(), "SQLite (*.sqlite3)");
if(!path.isEmpty()){
QSqlDatabase::database().close();
QSqlDatabase::database().removeDatabase(QSqlDatabase::database().connectionName());
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(path);
if(!db.open()){
QMessageBox::critical(this, tr("Error"), tr("DB Error"));
}
To copy to clipboard, switch view to plain text mode
But I always get the message that the database is still in use. AFAIR you cant get rid of this message with sqlite ... . But the new connection does work.
Bookmarks