From 4ec0baf312ec2b26b1dfbee34a22b2ef7dfeccf1 Mon Sep 17 00:00:00 2001 From: Jiewen Wang Date: Thu, 31 May 2012 08:00:25 -0400 Subject: 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: Id3d6ed15104d4d40c1cd2c76444c30badc8b1b72 Task-Id: QTBUG-25492 Backport of <7381328bcc37283be97eedddc24c46be1e38490e> from Qt5 Reviewed-by: Girish Ramakrishnan --- src/gui/widgets/qstatusbar.cpp | 2 -- tests/auto/qstatusbar/tst_qstatusbar.cpp | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/qstatusbar.cpp b/src/gui/widgets/qstatusbar.cpp index 7b668a6..38ceb6a 100644 --- a/src/gui/widgets/qstatusbar.cpp +++ b/src/gui/widgets/qstatusbar.cpp @@ -595,8 +595,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/qstatusbar/tst_qstatusbar.cpp b/tests/auto/qstatusbar/tst_qstatusbar.cpp index 56ea614..59733a9 100644 --- a/tests/auto/qstatusbar/tst_qstatusbar.cpp +++ b/tests/auto/qstatusbar/tst_qstatusbar.cpp @@ -78,6 +78,7 @@ private slots: void setSizeGripEnabled(); void task194017_hiddenWidget(); void QTBUG4334_hiddenOnMaximizedWindow(); + void QTBUG25492_msgtimeout(); private: QStatusBar *testWidget; @@ -277,5 +278,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" -- cgit v0.12