diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index fd34d26e10..928d7f9c4e 100644 --- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp @@ -1152,34 +1152,32 @@ public: void tst_QSpinBox::sizeHint() { - QWidget *widget = new QWidget; - QHBoxLayout *layout = new QHBoxLayout(widget); - widget->setLayout(layout); + QWidget widget; + QHBoxLayout *layout = new QHBoxLayout(&widget); + sizeHint_SpinBox *spinBox = new sizeHint_SpinBox; layout->addWidget(spinBox); - widget->show(); - QVERIFY(QTest::qWaitForWindowExposed(widget)); + // Make sure all layout requests posted by the QHBoxLayout constructor and addWidget + // are processed before the widget is shown + QCoreApplication::sendPostedEvents(&widget, QEvent::LayoutRequest); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); // Prefix spinBox->sizeHintRequests = 0; spinBox->setPrefix(QLatin1String("abcdefghij")); - qApp->processEvents(); QTRY_VERIFY(spinBox->sizeHintRequests > 0); // Suffix spinBox->sizeHintRequests = 0; spinBox->setSuffix(QLatin1String("abcdefghij")); - qApp->processEvents(); QTRY_VERIFY(spinBox->sizeHintRequests > 0); // Range spinBox->sizeHintRequests = 0; spinBox->setRange(0, 1234567890); spinBox->setValue(spinBox->maximum()); - qApp->processEvents(); QTRY_VERIFY(spinBox->sizeHintRequests > 0); - - delete widget; } void tst_QSpinBox::taskQTBUG_5008_textFromValueAndValidate()