View Full Version : saveState with multiple windows

29th September 2009, 03:39
I have an application based off of http://wiki.qtcentre.org/index.php?title=Extended_Main_Window which when closed saves the window state to a file keeping track of the dock widget positions and sizes using QMainWindow.saveState(). So the next time I open the application it comes up in the same configuration it was left in.

That works well for the example of the wiki but now I'd like to be able to tear off one of the dockwidgets into a separate dialog (not just a floating dock widget but actually in a separate QDialog/QMainWindow which may require reparenting...)

Is there a good way to save the application state in that case?

The only other thing I can think of is to tear the tool off into another QMainWindow and save the state of each main window into their own file and then create another file with the window positions/sizes and references to their saved state files. Any ideas?

29th September 2009, 10:16
But what is the exact problem? You can implement saveState() for your own widgets and use it to store their state in the byte array just as QMainWindow::saveState() does and then dump the blob to the same file as the original state. Then it's just a matter of reading byte arrays back and deciding which is related to which object (you can do that by using QObject::objectName()) and call restoreState().