How to Save custom DockWidgets
I want to save my custo开发者_如何学Cm DockWidgets (inherited from QDockWidget) with the saveState() / restoreState() function my MainWindow provides.
I have two questions: 1. How can I save and restore my Dockwidgets?
- I already tried registering my custom DockWidgets as a QMetaType and implementing the default Constructor, copy Constructor, Destructor and Streaming operators. 2. How can I identify the loaded DockWidgets? - For example: If 2 DockWidgets where saved and I load them with restoreState(), is there a way to get pointers to these loaded Widgets?Thanks, Tobias
Did you read the QMainWindow::saveState
documentation?
Are your objects uniquely named? (QObject::setObjectName
)
As a side note, QObjects should NOT have a copy constructor, see Q_DISABLE_COPY
I already solved question 2:
very easy .. QList<
QDockWidget*>
dockWidgetList = findChildren<
QDockWidget*>
();
But the list is currently empty after loading, because there is no widget being loaded ;)
It seems that you misunderstood something about restoreState - it will not recreate your dock widgets (how could it do anyway?) but will just restore their position and status (hidden, free or docked). You still have to create your dock widgets manually before invoking restoreState.
精彩评论