summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-12-29 11:44:04 (GMT)
committerJason McDonald <jason.mcdonald@nokia.com>2010-01-07 10:37:21 (GMT)
commitc221327673f3bbc50c0cdb9de068e133b05c2740 (patch)
treed692f03bd56e88bced00114ce68df0af9d3889a7
parente0c7d3a4561b23fc548471f910534f0fb57850ab (diff)
downloadQt-c221327673f3bbc50c0cdb9de068e133b05c2740.zip
Qt-c221327673f3bbc50c0cdb9de068e133b05c2740.tar.gz
Qt-c221327673f3bbc50c0cdb9de068e133b05c2740.tar.bz2
Fixes crash when widget with WA_StaticContents child become toplevel.
Happens for example if a DockWidget is undocked and has a child whith the WA_StaticContents attribute. The parent does not change (so newParent is false) but still, the top level widget change. So staticWidget need to be moved to the new backingstore. Reviewed-by: Benjamin Poulain Task-number: QTBUG-6883 (cherry picked from commit 03baad51d584778a99f4b393232ccc1312db3391)
-rw-r--r--src/gui/kernel/qwidget.cpp11
-rw-r--r--tests/auto/qwidget/tst_qwidget.cpp30
2 files changed, 34 insertions, 7 deletions
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp
index f6ae581..95d8413 100644
--- a/src/gui/kernel/qwidget.cpp
+++ b/src/gui/kernel/qwidget.cpp
@@ -9774,13 +9774,12 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
}
#endif
- if (newParent) {
- if (QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore()) {
+ if (QWidgetBackingStore *oldBs = oldtlw->d_func()->maybeBackingStore()) {
+ if (newParent)
oldBs->removeDirtyWidget(this);
- // Move the widget and all its static children from
- // the old backing store to the new one.
- oldBs->moveStaticWidgets(this);
- }
+ // Move the widget and all its static children from
+ // the old backing store to the new one.
+ oldBs->moveStaticWidgets(this);
}
if ((QApplicationPrivate::app_compile_version < 0x040200
diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp
index 7039f06..7405704 100644
--- a/tests/auto/qwidget/tst_qwidget.cpp
+++ b/tests/auto/qwidget/tst_qwidget.cpp
@@ -66,6 +66,8 @@
#include <private/qapplication_p.h>
#include <qcalendarwidget.h>
#include <qmainwindow.h>
+#include <qdockwidget.h>
+#include <qtoolbar.h>
#include <QtGui/qpaintengine.h>
#include <private/qbackingstore_p.h>
@@ -356,6 +358,7 @@ private slots:
void paintOnScreenPossible();
#endif
void reparentStaticWidget();
+ void QTBUG6883_reparentStaticWidget2();
#ifdef Q_WS_QWS
void updateOutsideSurfaceClip();
#endif
@@ -8728,6 +8731,31 @@ void tst_QWidget::reparentStaticWidget()
// Please don't crash.
paintOnScreen.resize(paintOnScreen.size() + QSize(2, 2));
QTest::qWait(20);
+
+}
+
+void tst_QWidget::QTBUG6883_reparentStaticWidget2()
+{
+ QMainWindow mw;
+ QDockWidget *one = new QDockWidget("one", &mw);
+ mw.addDockWidget(Qt::LeftDockWidgetArea, one , Qt::Vertical);
+
+ QWidget *child = new QWidget();
+ child->setPalette(Qt::red);
+ child->setAutoFillBackground(true);
+ child->setAttribute(Qt::WA_StaticContents);
+ child->resize(100, 100);
+ one->setWidget(child);
+
+ QToolBar *mainTools = mw.addToolBar("Main Tools");
+ mainTools->addWidget(new QLineEdit);
+
+ mw.show();
+ QTest::qWaitForWindowShown(&mw);
+
+ one->setFloating(true);
+ QTest::qWait(20);
+ //do not crash
}
#ifdef Q_WS_QWS
@@ -9726,7 +9754,7 @@ public:
void deleteBackingStore()
{
if (static_cast<QWidgetPrivate*>(d_ptr.data())->maybeBackingStore()) {
- delete static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStore;
+ delete static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStore;
static_cast<QWidgetPrivate*>(d_ptr.data())->topData()->backingStore = 0;
}
}