From 7381328bcc37283be97eedddc24c46be1e38490e Mon Sep 17 00:00:00 2001 From: Jiewen Wang Date: Fri, 25 May 2012 08:13:11 -0400 Subject: [PATCH] QStatusBar::showMessage will always take new timeout There is a message check in QStatusBar::showMessage causing the call exits early if the new 'message' is the same as the current message. The check has been removed, and new timeout will always take effect. Unit test is added as well. Change-Id: I3a03c6842835824caba4adc37c3ed834952c4bb2 Task-Id: QTBUG-25492 Reviewed-by: Girish Ramakrishnan --- src/widgets/widgets/qstatusbar.cpp | 2 - .../widgets/qstatusbar/tst_qstatusbar.cpp | 45 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/widgets/widgets/qstatusbar.cpp b/src/widgets/widgets/qstatusbar.cpp index 2b17d7fb83..4e6b273a3c 100644 --- a/src/widgets/widgets/qstatusbar.cpp +++ b/src/widgets/widgets/qstatusbar.cpp @@ -546,8 +546,6 @@ void QStatusBar::reformat() void QStatusBar::showMessage(const QString &message, int timeout) { Q_D(QStatusBar); - if (d->tempItem == message) - return; d->tempItem = message; diff --git a/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp b/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp index d23f69ac6c..ca54564d24 100644 --- a/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp +++ b/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp @@ -73,6 +73,7 @@ private slots: void setSizeGripEnabled(); void task194017_hiddenWidget(); void QTBUG4334_hiddenOnMaximizedWindow(); + void QTBUG25492_msgtimeout(); private: QStatusBar *testWidget; @@ -276,5 +277,49 @@ void tst_QStatusBar::QTBUG4334_hiddenOnMaximizedWindow() QVERIFY(!statusbar.findChild()->isVisible()); } +void tst_QStatusBar::QTBUG25492_msgtimeout() +{ + QVERIFY(testWidget->currentMessage().isNull()); + QVERIFY(currentMessage.isNull()); + testWidget->show(); + + // Set display message forever first + testWidget->showMessage("Ready", 0); + QCOMPARE(testWidget->currentMessage(), QString("Ready")); + QCOMPARE(testWidget->currentMessage(), currentMessage); + + QTest::qWait(1000); + + // Set display message for 2 seconds again + testWidget->showMessage("Ready", 2000); + QCOMPARE(testWidget->currentMessage(), QString("Ready")); + QCOMPARE(testWidget->currentMessage(), currentMessage); + + QTest::qWait(3000); + + // Message disappears after 2 seconds + QVERIFY(testWidget->currentMessage().isNull()); + QVERIFY(currentMessage.isNull()); + + // Set display message for 2 seconds first + testWidget->showMessage("Ready 25492", 2000); + QCOMPARE(testWidget->currentMessage(), QString("Ready 25492")); + QCOMPARE(testWidget->currentMessage(), currentMessage); + + QTest::qWait(1000); + + // Set display message forever again + testWidget->showMessage("Ready 25492", 0); + QCOMPARE(testWidget->currentMessage(), QString("Ready 25492")); + QCOMPARE(testWidget->currentMessage(), currentMessage); + + QTest::qWait(3000); + + // Message displays forever + QCOMPARE(testWidget->currentMessage(), QString("Ready 25492")); + QCOMPARE(testWidget->currentMessage(), currentMessage); +} + + QTEST_MAIN(tst_QStatusBar) #include "tst_qstatusbar.moc"