如果我们希望保存所有可停靠物件和工具栏的位置以便我们能在程序下次运行时恢复它们,使用QMainWindow的saveState() 和 restoreState() 函数:
void MainWindow::writeSettings()
{
QSettings settings("Software Inc.","Icon Editor");
settings.beginGroup("mainWindow");
settings.setValue("size", size());
settings.setValue("state", saveState());
settings.endGroup();
}
void MainWindow::readSettings()
{
QSettings settings("Software Inc.","Icon Editor");
settings.beginGroup("mainWindow");
resize(settings.value("size").toSize());
restoreState(settings.value("state").toByteArray());
settings.endGroup();
}