PDA

View Full Version : 4.2 saveState



merlvingian
16th October 2006, 02:30
Pieced together some quick POC code, but I believe it covers the major points. QDockWidgets do not appear to be saving state correctly with QMainWindow::saveState. Results vary with dock resizing, floating, and when not visible. I did not see this behavior in 4.1.4 open source, and tried to put together a quick poc rather then the large amount of code from my project for confirmation.

I am not using MiniGW and am unclear if this is a problem with patches to the open source version, 4.2 changes, my horrid programing, or some change I am missing. The test I ran with the code example was on a WinXP system.

main.h

#ifndef _MAIN_H_
#define _MAIN_H_

#include <QMainWindow>
#include <QDockWidget>
#include <QTextEdit>

class MainWindow : public QMainWindow {

Q_OBJECT

public:
MainWindow();

void readSettings();
void writeSettings();

QTextEdit *textEdit;

QDockWidget *d1;
QDockWidget *d2;
QDockWidget *d3;

protected:
void closeEvent(QCloseEvent *event);

};

#endif

main.cpp

#include <QtGui>
#include <QApplication>

#include "main.h"

MainWindow::MainWindow() {

textEdit = new QTextEdit;
setCentralWidget(textEdit);

d1 = new QDockWidget(tr("Dock1"));
d1->setObjectName(tr("d1"));

d2 = new QDockWidget(tr("Dock2"));
d2->setObjectName(tr("d2"));

d3 = new QDockWidget(tr("Dock3"));
d3->setObjectName(tr("d3"));

addDockWidget(Qt::RightDockWidgetArea, d1);
addDockWidget(Qt::LeftDockWidgetArea, d2);
addDockWidget(Qt::TopDockWidgetArea, d3);


readSettings();
}

void MainWindow::readSettings() {

QSettings settings("poc.ini",QSettings::IniFormat);

settings.beginGroup("session");
restoreState(settings.value("Layout").toByteArray());
QRect rect = settings.value("MainWindowGeometry",
QRect(0, 0, 780, 520)).toRect();
move(rect.topLeft());
resize(rect.size());
settings.endGroup();
}

void MainWindow::writeSettings() {

QSettings settings("poc.ini",QSettings::IniFormat);

settings.beginGroup("session");
settings.setValue("MainWindowGeometry", geometry());

settings.remove("Layout");
settings.setValue("Layout",saveState());
settings.endGroup();

}

void MainWindow::closeEvent(QCloseEvent *event)
{
writeSettings();
event->accept();
}

int main(int argc, char *argv[]) {

QApplication app(argc, argv);
MainWindow mainwindow;
mainwindow.show();

return app.exec();
}


Some things you can try are:
1. If you close a dock, and reload it will not remember it is closed.
1a. Now if you had a dock nested in another and closed it, QMAinWindow::saveState will remember it was closed
2. Moving a dock to another position will be remember.
2a.Move a dock to another position and then close another, with 3 dockwidgets can cause all to be reset to default positioning.
3. Float one dock and close another, will cause all 3 to reset to default positioning.

fullmetalcoder
16th October 2006, 07:27
In readSettings() : move the geometry restoration before restoreState() and see if it helps...

merlvingian
16th October 2006, 20:19
In readSettings() : move the geometry restoration before restoreState() and see if it helps...

No change :crying:

Anyone with commercial 4.2 experiencing this behavior? I do not have access to a linux distro to test in that environment at this time.

merlvingian
22nd October 2006, 02:34
Anyone else able to produce this result from the code sample? :confused:

jpn
22nd October 2006, 13:42
Task Tracker - Entry 135551 (http://www.trolltech.com/developer/task-tracker/index_html?method=entry&id=135551) - QMainWindow::saveState() doesn't save floating dockwidgets

merlvingian
22nd October 2006, 21:42
Task Tracker - Entry 135551 (http://www.trolltech.com/developer/task-tracker/index_html?method=entry&id=135551) - QMainWindow::saveState() doesn't save floating dockwidgets

It states it is in version 4.1.4 - I can not get the bug to reproduce in 4.1.4 open source only 4.2.0, unless it is referring to restoreState from a 4.0.1 save in 4.1.4.

I will do some more research into the issue and see what is required in order to submit information to the task tracker.

Thank you for your help on the issue.

EricF
1st November 2007, 15:24
Reviving old thread. I'm using 4.3.2 so this bug should be fixed. However, my floating widgets don't show. When I show them, they have the right size and position but the visible flag doesn't seem to be saved.

Any thoughts ?