PDA

View Full Version : Problem in restoring more than one QDockWidget



vratojr
10th March 2006, 13:37
Hello,
I have a mw with 2 dockwidget that I'd like to restore at start.
Here is the code I use:



dockInfo = new DockWindow(widgetInfo->windowTitle());
addDockWidget(Qt::TopDockWidgetArea,dockInfo);
dockInfo->setWidget(widgetInfo);
dockInfo->hide();

dockScancella = new DockWindow(widgetScancella->windowTitle());
addDockWidget(Qt::BottomDockWidgetArea,dockScancel la);
dockScancella->setWidget(widgetScancella);
dockScancella->hide();

restoreState(stato);

and,during the closeEvent function I save the state of the window using


stato=saveState();

and write it to file.

Well, if I use 1 of the 2 dock widget (I mean I comment the code regarding the other) I have no problem and I can restore the whole system.
If I use both the widgets, the bytearray representing the savingstate becomes more and more larger at each time I save the state. Moreover the widgets are nore restored correctly (they are restored randomly) in particular,sometimes, one of the 2 appears to be multiplied on screen and each copy is flickering.

any hints?

Thanks!

Chicken Blood Machine
10th March 2006, 17:12
I could be totally off here, but could you verify what happens if you give each dock widget a unique name with setObjectName()? Also, try giving each dock widget a unique window title.

vratojr
13th March 2006, 08:45
I could be totally off here, but could you verify what happens if you give each dock widget a unique name with setObjectName()? Also, try giving each dock widget a unique window title.

Thanks for the answer but I'm yet using different object names and window titles.

ldindon
13th March 2006, 13:45
Yop

Maybe it is due to a problem of charachters conversion when you read/write to/from your saving file.

Try to use the power of QSettings by doing something like that:


//------------------------------------------------------------------------------
/**
*/
//------------------------------------------------------------------------------
void
MyMainWindow::saveWindowState()
{
QSettings l_settings("MyCompanyName", "MyAppName");

l_settings.beginGroup("MainWindow");
l_settings.setValue("size", this->size());
l_settings.setValue("pos", this->pos());
l_settings.setValue("state", this->saveState());
l_settings.endGroup();
}

//------------------------------------------------------------------------------
/**
*/
//------------------------------------------------------------------------------
void
MyMainWindow::restoreWindowState()
{
QSettings l_settings("MyCompanyName", "MyAppName");

// Default size and position
QRect l_rect = QApplication::desktop()->availableGeometry(0);


l_settings.beginGroup("MainWindow");
this->resize(l_settings.value("size", l_rect.size()).toSize());
this->move(l_settings.value("pos", l_rect.topLeft()).toPoint());
this->restoreState(l_settings.value("state", QByteArray()).toByteArray());
l_settings.endGroup();

Works fine for me with 3 toolbars and about 6 dockwidgets...

}