Widgets: Do not create QWindow in createTLExtra().

QWidget::setWindowIcon() and similar call createTLExtra()
which creates a QWindow without setting the native attributes
on the parent, which can cause crashes when setParent_sys()
decides to delete the window.

Task-number: QTBUG-31672

Change-Id: I4c40ee12741be88b2281df90329ffb698d4009eb
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
Friedemann Kleint 2013-06-12 12:52:31 +02:00 committed by The Qt Project
parent b6f2442371
commit 0bc96d1d6b
2 changed files with 5 additions and 4 deletions

View File

@ -1546,10 +1546,11 @@ void QWidgetPrivate::createTLExtra()
x->inTopLevelResize = false;
x->inRepaint = false;
x->embedded = 0;
x->window = 0;
x->screenIndex = 0;
#ifdef Q_WS_MAC
x->wasMaximized = false;
#endif // Q_WS_MAC
createTLSysExtra();
#ifdef QWIDGET_EXTRA_DEBUG
static int count = 0;
qDebug() << "tlextra" << ++count;
@ -10109,6 +10110,8 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
break; }
case Qt::WA_NativeWindow: {
d->createTLExtra();
if (on)
d->createTLSysExtra();
#ifndef QT_NO_IM
QWidget *focusWidget = d->effectiveFocusWidget();
if (on && !internalWinId() && hasFocus()

View File

@ -890,9 +890,7 @@ void QWidgetPrivate::deleteSysExtra()
void QWidgetPrivate::createTLSysExtra()
{
Q_Q(QWidget);
extra->topextra->screenIndex = 0;
extra->topextra->window = 0;
if (q->testAttribute(Qt::WA_NativeWindow) || q->isWindow()) {
if (!extra->topextra->window && (q->testAttribute(Qt::WA_NativeWindow) || q->isWindow())) {
extra->topextra->window = new QWidgetWindow(q);
if (extra->minw || extra->minh)
extra->topextra->window->setMinimumSize(QSize(extra->minw, extra->minh));