Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.2, 4.8.4, 5.0.1
-
18f9eb797bffe8626f1edeca3c88f80dae0da8d7 (5.1), 5a58067a8ed92553182467a3522aff7747a22cad (4.8)
Description
The method QStackedLayout::setCurrentIndex() does the following
1. Store the window's focusWidget() in a local variable
2. hide the old widget
3. show the new widget
4. try to set a sensible new focus widget
When a widget creates its internal structure in its showEvent() and tears down some internal widgets in the hideEvent(), it can happen that the old focus widget is destroyed in step 2 and step 4 uses a dangling pointer.
Solution: Use a QPointer instead:
--- qstackedlayout.cpp.old 2011-03-21 08:10:35.117951000 +0100 +++ qstackedlayout.cpp 2011-03-21 07:57:43.263064000 +0100 @@ -301,7 +301,7 @@ parent->setUpdatesEnabled(false); } - QWidget *fw = parent ? parent->window()->focusWidget() : 0; + QPointer<QWidget> fw = parent ? parent->window()->focusWidget() : 0; if (prev) { prev->clearFocus(); if (d->stackingMode == StackOne)