waynew
29th January 2010, 01:17
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() {
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();
}
saving ba size with debug shows 93
Now restoring the state called from the constructor.
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();
}
debug shows restore state ba size is 93.
What's wrong here?
// 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();
}
saving ba size with debug shows 93
Now restoring the state called from the constructor.
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();
}
debug shows restore state ba size is 93.
What's wrong here?