什么是保存Qt GUI状态的最佳适当方式,以便在重新打开应用程序时恢复与关闭前相同的状态?
所谓状态是指:在关闭应用程序之前的当前索引(如组合框...),颜色调色板,小部件位置等。
什么是保存Qt GUI状态的最佳适当方式,以便在重新打开应用程序时恢复与关闭前相同的状态?
所谓状态是指:在关闭应用程序之前的当前索引(如组合框...),颜色调色板,小部件位置等。
void MainWindow::writeSettings()
{
QSettings settings("reaffer Soft", "reafferApp");
settings.beginGroup("MainWindow");
settings.setValue("size", size());
settings.setValue("pos", pos());
settings.endGroup();
}
void MainWindow::readSettings()
{
QSettings settings("reaffer Soft", "reafferApp");
settings.beginGroup("MainWindow");
resize(settings.value("size", QSize(400, 400)).toSize());
move(settings.value("pos", QPoint(200, 200)).toPoint());
settings.endGroup();
}
MainWindow::MainWindow()
{
// code from constructor
//...
readSettings();
}
void MainWindow::closeEvent(QCloseEvent *event)
{
//optional check if the user really want to quit
// and/or if the user want to save settings
writeSettings();
event->accept();
}
QSettings settings("Organisation", "MySoftware");
settings.beginGroup("WindowNumberTwo");
settings.setValue("ComboIndex", combobox->currentIndex());
// save more values here
// ...
settings.endGroup();