Вы можете использовать класс QSettings.
Это простой пример:
widget.h
#define WIDGET_H
#include <QWidget>
#include <QSettings>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
private:
QString lastDir;
QSettings *settings;
void settingsLoader();
void settingsSaver();
};
#endif // WIDGET_H
widget.cpp
#include <QFileDialog>
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
settings = new QSettings("MyCompany", "My soft name", this);
settingsLoader();
lastDir = QFileDialog::getExistingDirectory(this, tr("Open directory"), lastDir);
}
void Widget::settingsLoader()
{
lastDir = settings->value("LastDir", QDir::homePath()).toString();
}
void Widget::settingsSaver()
{
settings->setValue("LastDir", lastDir);
}
Widget::~Widget()
{
settingsSaver();
}