Can't seem to get this to work. I'm trying to save the mainwindow state to a database and restore it on startup so the window size and position will be the same as when the application was quit. The problem is that the size and positions don't get restored.
// saving the state - this is called in the closeEvent:
void MainWindow::saveSettings() {
ba = saveState();
qDebug() << "saving ba size is " << ba.size();
query.prepare("UPDATE settings set state=? where id=1");
query.addBindValue(ba);
query.exec();
qDebug() << "saving state " << query.lastError();
}
// saving the state - this is called in the closeEvent:
void MainWindow::saveSettings() {
QByteArray ba;
ba = saveState();
qDebug() << "saving ba size is " << ba.size();
QSqlDatabase db = QSqlDatabase::database(ctrlConn);
QSqlQuery query(db);
query.prepare("UPDATE settings set state=? where id=1");
query.addBindValue(ba);
query.exec();
qDebug() << "saving state " << query.lastError();
}
To copy to clipboard, switch view to plain text mode
saving ba size with debug shows 93
Now restoring the state called from the constructor.
void MainWindow::restoreSettings() {
query.exec("SELECT state from settings where id = 1");
query.last();
qDebug() << "restoring ba size is " << ba.size();
restoreState(ba);
qDebug() << "restoring state " << query.lastError();
}
void MainWindow::restoreSettings() {
QSqlDatabase db = QSqlDatabase::database(ctrlConn);
QSqlQuery query(db);
query.exec("SELECT state from settings where id = 1");
query.last();
QByteArray ba = query.value(0).toByteArray();
qDebug() << "restoring ba size is " << ba.size();
restoreState(ba);
qDebug() << "restoring state " << query.lastError();
}
To copy to clipboard, switch view to plain text mode
debug shows restore state ba size is 93.
What's wrong here?
Bookmarks