dockmanager savesate only save the layout of first dock area
BarryArch opened this issue · 5 comments
I want to save the dock layout to a file and reload it when reopen.
the code of save dock layout :
QFile file("VisualLayout.ini");
if (file.open(QIODevice::WriteOnly))
{
QDataStream out(&file);
out << _dockMan->saveState();
file.close();
}
and the code of load the config file:
QFile file("VisualLayout.ini");
if (file.open(QIODevice::ReadOnly))
{
QByteArray ba;
QDataStream in(&file);
in >> ba;
file.close();
if (_dockMan->restoreState(ba))
{
qDebug() << QString("good");
}
else
{
qDebug() << QString("failed");
}
}
but it just reload the 1st dock area layout, and totally ignored other dock area.
Please have a look into the demo application to learn how to save and restore dock manager states.
I have learned from the demo application, and modified the code like :
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
// ....
restoreSettings();
}
MainWindow::~MainWindow()
{
}
void MainWindow::closeEvent(QCloseEvent * event)
{
saveSettings();
_dockMan->deleteLater();
QMainWindow::closeEvent(event);
}
void MainWindow::saveSettings()
{
QSettings settings("Settings.ini", QSettings::IniFormat);
settings.setValue("mainWindow/Geometry", saveGeometry());
settings.setValue("mainWindow/State", saveState());
settings.setValue("mainWindow/DockingState", _dockMan->saveState());
}
void MainWindow::restoreSettings()
{
QSettings settings("Settings.ini", QSettings::IniFormat);
restoreGeometry(settings.value("mainWindow/Geometry").toByteArray());
restoreState(settings.value("mainWindow/State").toByteArray());
_dockMan->restoreState(settings.value("mainWindow/DockingState").toByteArray());
}
But it just doesn't work , dockmanager savesate still only save the layout of first dock area. Is there any key point that I have overlooked here? I really need your help .
Does save and restore work in the demo application?
Indeed, your demo program is functioning very well. However, I feel that my method of usage has been correct and in line with your demo program. Is there perhaps some key aspect that I might have overlooked?
DockWidget must have a widget set in order to be reloaded from configuration. This note is recorded here for anyone who might encounter the same issue.