[SOLVED] save and restore window / dialog positions
-
I would like to save my mainwindow, dialogs and toolbar positions. I am having a difficult time implementing the save and restore geometry code found "here.":http://developer.qt.nokia.com/wiki/Saving_Window_Size_State the problem is that i don't know how to create the savegeometry and savestate functions.
can I have a working example that works with x11 please.
-
You don't have to create them. They're already provided by "QWidget":http://doc.qt.nokia.com/4.7/qwidget.html#restoreGeometry (unless you're using a version of Qt older than 4.2). If your class inherits QWidget, then you can just call the methods.
-
I am have a problem with line 24 / 25 of the code. I am getting the error mainwindow.cpp:24: error: 'saveGeometry' was not declared in this scope and mainwindow.cpp:25: error: 'saveState' was not declared in this scope.
do i have to create the saveGeometry and saveState functions? I need examples for this code please.
@#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QWidget>
#include <QSettings>MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QSettings settings;restoreGeometry(settings.value("mainWindowGeometry").toByteArray()); // create docks, toolbars, etc... restoreState(settings.value("mainWindowState").toByteArray());
}
void closeEvent(QCloseEvent *event) {
QSettings settings;
settings.setValue("mainWindowGeometry", saveGeometry());
settings.setValue("mainWindowState", saveState());
}MainWindow::~MainWindow()
{
delete ui;
}@ -
i solved it. i needed the following code in the main.cpp file
@ QCoreApplication::setOrganizationDomain("OrgDomain");
QCoreApplication::setOrganizationName("OrgName");
QCoreApplication::setApplicationName("AppName");
QCoreApplication::setApplicationVersion("1.0.0");@ -
"here":http://developer.qt.nokia.com/doc/qt-4.7/qapplication.html#id-7292984e-d337-4916-bbdf-6b5499d193c1 is the link from the save state quote below
[quote]This function deals with session management. It is invoked when the session manager wants the application to preserve its state for a future session.For example, a text editor would create a temporary file that includes the current contents of its edit buffers, the location of the cursor and other aspects of the current editing session.
You should never exit the application within this function. Instead, the session manager may or may not do this afterwards, depending on the context. Futhermore, most session managers will very likely request a saved state immediately after the application has been started. This permits the session manager to learn about the application's restart policy.[/quote]
one last question. above is a quote about saveStates. the savestate code that I have in my program (see below code), will my program exit within this saveState function?
@settings.setValue("mainWindowState", saveState());@