diff options
author | Andreas Aardal Hanssen <andreas@hanssen.name> | 2013-02-15 18:04:07 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-18 11:07:23 +0100 |
commit | 843de37bca944110fdf3aab161d680e3845d2dd2 (patch) | |
tree | e85cb3618be4e2740f89ab2d396a0f22445d9364 /src/widgets/kernel | |
parent | 615d120e5a3ccbda82dfa6eeaa445c613adc7ca2 (diff) |
Remove QGraphicsProxyWidget crash in QWidget::hasFocus().
A QGraphicsProxyWidget embeds a focusable widget (e.g., QComboBox). When
deleting QGraphicsProxyWidget, the QWidget will be deleted. The QWidget
clears focus, and QWidget::hasFocus() is nice enough to check if its
embedder QGraphicsProxyWidget has focus - because if it does, it wants
to clear focus from that item too. QGraphicsItem's destructor already
calls clearFocus() however, so this call is unnecessary; we can simply
stop clearing the QWidget's focus in its destructor if the widget is
embedded.
QWidget::hasFocus checks QGraphicsItem::hasFocus (on the proxy widget
that is being deleted), which checks its d_ptr, which is gone. It's
generally unfavorable for an object deleting a child to have the child
go back and poke at the parent object, which is in many ways what's
happening here.
Task-number: QTBUG-29684
Change-Id: I1e52bf28f47b2824752de28dff2d0de13733ee48
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 7209d8c9ad..5ec713140e 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1391,6 +1391,14 @@ QWidget::~QWidget() QT_TRY { +#ifndef QT_NO_GRAPHICSVIEW + const QWidget* w = this; + while (w->d_func()->extra && w->d_func()->extra->focus_proxy) + w = w->d_func()->extra->focus_proxy; + QWidget *window = w->window(); + QWExtra *e = window ? window->d_func()->extra : 0; + if (!e || !e->proxyWidget) +#endif clearFocus(); } QT_CATCH(...) { // swallow this problem because we are in a destructor |