Dock widget not visible
Unsolved
General and Desktop
-
I have a dock widget that's owned by a QDialog that may not be visible under all circumstances when the application is closed and the window state is saved.
When I restart I want to show this dialog and the dock widget.
So in onInitialise() that I call from here:
void DeepSkyStacker::showEvent(QShowEvent* event) { // Invoke base class showEvent() Inherited::showEvent(event); if (!event->spontaneous()) { if (!initialised) { initialised = true; onInitialise(); } } }
I wrote:
stackingDlg->setVisible(true); setTab(IDD_REGISTERING); update();
which in turn called code that did this:
stackedWidget->setCurrentIndex(0); stackingDlg->showImageList(); stackingDlg->update();
where the call to stackingDlg->showImageList() calls setVisible(true) for the dock widget.
Problem is that it didn't work :(
In the end, in a fit of desperation, I changed the code in onInitialise() to read:
QTimer::singleShot(20, [this]() { this->stackingDlg->setVisible(true); this->setTab(IDD_REGISTERING); this->update(); });
and lo it all works as I expect.
Please can someone explain why I needed to put that code into a single shot?