//需要使用QSetting
#include<QSettings>
声明函数
protected:
void closeEvent(QCloseEvent *event);
private:
void wirteSettings();
void readSettings();
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
……
readSettings();//页面设置完成,加载ini配置文件
}
//重构关闭函数
void MainWindow::closeEvent(QCloseEvent *event)
{
……
wirteSettings();
……
}
//保存页面布局到配置文件
void MainWindow::wirteSettings()
{
QSettings settings("xmutyh","ELsoft");
settings.beginGroup("mainWindow");
settings.setValue("size",size());
settings.setValue("state",saveState());
tings.setValue("lineeditor",ui->lineEdit->text());//保存输入框内容
settings.endGroup();
}
//恢复页面布局
void MainWindow::readSettings()
{
QSettings settings("xmutyh","ELsoft");
settings.beginGroup("mainWindow");
resize(settings.value("size").toSize());
restoreState(settings.value("state").toByteArray());
ui->lineEdit->setText(settings.value("lineeditor").toString());//返回输入框内容
settings.endGroup();
}
http://blog.csdn.net/yh_1988/article/details/6752478