I try to open two seperate SQLite databases at the same time using code below. Why do I get message that the first DB is not opened?
base1.setDatabaseName(pot);
base1.open();
base2.setDatabaseName(qApp->applicationDirPath() + "/base.db");
base2.open();
if (base1.isOpen() != TRUE) {
QMessageBox::critical(this,
"Dnevnik",
"Error opening DB 1");
}
else {
if(base2.isOpen() != TRUE){
QMessageBox::critical(this,
"Dnevnik",
"Error opening DB 2");
}
else {
//some code to execute
}
}
base2.close();
base1.close();
QSqlDatabase base1 = QSqlDatabase::addDatabase("QSQLITE");
QString pot = ui.p_odpri->text();
base1.setDatabaseName(pot);
base1.open();
QSqlDatabase base2 = QSqlDatabase::addDatabase("QSQLITE");
base2.setDatabaseName(qApp->applicationDirPath() + "/base.db");
base2.open();
if (base1.isOpen() != TRUE) {
QMessageBox::critical(this, "Dnevnik", "Error opening DB 1");
}
else {
if(base2.isOpen() != TRUE){
QMessageBox::critical(this, "Dnevnik", "Error opening DB 2");
}
else {
//some code to execute
}
}
base2.close();
base1.close();
To copy to clipboard, switch view to plain text mode
If I use code below everything works just fine...
base1.setDatabaseName(pot);
base1.open();
if (base1.isOpen() != TRUE) {
QMessageBox::critical(this,
"Dnevnik",
"Error opening DB 1");
}
else {
base2.setDatabaseName(qApp->applicationDirPath() + "/base.db");
base2.open();
if(base2.isOpen() != TRUE){
QMessageBox::critical(this,
"Dnevnik",
"Error opening DB 2");
}
else {
//some code to execute
}
base2.close();
}
base1.close();
QSqlDatabase base1 = QSqlDatabase::addDatabase("QSQLITE");
QString pot = ui.p_odpri->text();
base1.setDatabaseName(pot);
base1.open();
if (base1.isOpen() != TRUE) {
QMessageBox::critical(this, "Dnevnik", "Error opening DB 1");
}
else {
QSqlDatabase base2 = QSqlDatabase::addDatabase("QSQLITE");
base2.setDatabaseName(qApp->applicationDirPath() + "/base.db");
base2.open();
if(base2.isOpen() != TRUE){
QMessageBox::critical(this, "Dnevnik", "Error opening DB 2");
}
else {
//some code to execute
}
base2.close();
}
base1.close();
To copy to clipboard, switch view to plain text mode
Can somebody explain what I do with the first and what with the second code?
Regards,
Luka
Bookmarks