代码是这样的:
file - > Conf.cpp
#include <QWidget>
#include <QSettings>
#include <QMainWindow>
Conf::Conf(QWidget *parent) :
QWidget(parent),
ui(new Ui::Conf)
{
ui->setupUi(this);
//QCoreApplication :: setOrganizationDomain ("OrgDomain");
//QCoreApplication :: setOrganizationName ("OrgName");
//QCoreApplication :: setApplicationName ("AppName");
//QCoreApplication :: setApplicationVersion ("1.0.0");
QSettings settings;
restoreGeometry(settings.value("mainWindowGeometry").toByteArray());
restoreState(settings.value("mainWindowState").toByteArray());
}
Conf::~Conf()
{
delete ui;
}
void Conf::on_pushButton_clicked()
{
......
QSettings settings;
settings.setValue("mainWindowGeometry", saveGeometry());
settings.setValue("mainWindowState", saveState());
close();
}
file - &gt; Conf.h
#include <QWidget>
namespace Ui {
class Conf;
}
class Conf : public QWidget
{
Q_OBJECT
public:
explicit Conf(QWidget *parent = 0);
~Conf();
private slots:
void on_pushButton_clicked();
private:
Ui::Conf *ui;
};
错误:
&#39; restoreStates&#39;未在此范围内声明
&#39; saveStates&#39;未在此范围内声明
我认为这个问题属于库,因为&#34; restoreGeometry&#34;和&#34; saveGeometry&#34;效果很好。
答案 0 :(得分:0)
您的类继承到QWidget,但QWidget没有任何restoreState和saveState。它出现在QMainWindow。