PDA

View Full Version : QSplitter::restoreState() not working



PeterThePuter
22nd October 2010, 05:35
Hey all!

I have a quick question: When using a splitter, I would like it to restore itself to the position it was at last time the application closed. I have been able to restore the main window's geometry just fine, but when attempting to restore a splitter, it doesn't work.

When the application starts:

QSettings settings;

// Main window settings
settings.beginGroup("mainWindow");
restoreGeometry(settings.value("geometry").toByteArray());
splitter->restoreState(settings.value("splitterState").toByteArray());
settings.endGroup();

When a close event is called:

QSettings settings;

// Main window settings
settings.beginGroup("mainWindow");
settings.setValue("geometry", saveGeometry());
settings.setValue("splitterState", splitter->saveState());
settings.endGroup();

The splitter always starts in the middle, regardless of where I leave it at close.

Any help?

wladek
25th October 2010, 12:32
Hi PeterThePuter,

I also tested this and noticed that you can correctly save into QSettings object only if you define the organizationName on the QApplication object.
Something like this:


QApplication a(argc, argv);
a.setOrganizationName("TestSplitter");

franc0is
14th February 2014, 16:39
Hello,

I have exactly the same issue. The issue is not in saving the
QSplitter state. I am sure that the data is well stored and read
from my settings file.

The issue is that, in some case, the QSplitter is not restored.

PeterThePuter, did you solve that issue?

Thanks