Quantcast
Viewing all articles
Browse latest Browse all 13965

[SOLVED] QSqlDatabase::addDatabase("QSQLITE","localdb"); problem with name

With this code in the constructor of my mainwindow:     db = QSqlDatabase::addDatabase("QSQLITE","localdb");     db.setDatabaseName("../test/test.db");     if (!db.open()) {         QMessageBox::critical(0, QObject::tr("Database Error"),                               db.lastError().text());     }       model = new QSqlTableModel(this);     model->setTable("items");     model->select();     qDebug() << "SQL LastError:" << model->lastError().text(); and in the destructor:     db.close();     QSqlDatabase::removeDatabase("localdb");     delete ui; output at start: (I don’t have the qmessagebox and my table view stay blank.) SQL LastError: “ Unable to find table items” output at close app: QSqlDatabasePrivate::removeDatabase: connection ‘localdb’ is still in use, all queries will cease to work. If I remove the name of the connection, “localdb” and let the system use the default name, I have this:     db = QSqlDatabase::addDatabase("QSQLITE"); SQL LastError: “ “ and I have my datas shown in the table view… ?!?!? No error at close. What am I doing wrong with the connection name? I need it because this app will have 2 separates connections, one local with sqlite and another to a remote db2 server.

Viewing all articles
Browse latest Browse all 13965

Trending Articles