From 8ac7e812604d24fcbf28132a611d3b3e06120349 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Wed, 26 Aug 2009 20:49:32 +0200 Subject: Do not crash when double-clicking a tab in a QTabBar with movable tabs Check if QTabBarPrivate's movingTab member is 0 before dereferencing it. This fixes a crash when double-clicking a tab. New unit test included. http://bugs.kde.org/show_bug.cgi?id=202767 Reviewed-by: Olivier Goffart Merge-Request: 1337 --- src/gui/widgets/qtabbar.cpp | 3 ++- tests/auto/qtabbar/tst_qtabbar.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qtabbar.cpp b/src/gui/widgets/qtabbar.cpp index 5166390..d8246c8 100644 --- a/src/gui/widgets/qtabbar.cpp +++ b/src/gui/widgets/qtabbar.cpp @@ -1836,7 +1836,8 @@ void QTabBarPrivate::moveTabFinished(int index) } #endif //QT_NO_ANIMATION if (allAnimationsFinished && cleanup) { - movingTab->setVisible(false); // We might not get a mouse release + if(movingTab) + movingTab->setVisible(false); // We might not get a mouse release for (int i = 0; i < tabList.count(); ++i) { tabList[i].dragOffset = 0; } diff --git a/tests/auto/qtabbar/tst_qtabbar.cpp b/tests/auto/qtabbar/tst_qtabbar.cpp index 041836c..3f77b7a 100644 --- a/tests/auto/qtabbar/tst_qtabbar.cpp +++ b/tests/auto/qtabbar/tst_qtabbar.cpp @@ -94,6 +94,7 @@ private slots: void moveTab(); void task251184_removeTab(); + void changeTitleWhileDoubleClickingTab(); }; // Testing get/set functions @@ -535,5 +536,38 @@ void tst_QTabBar::task251184_removeTab() } +class TitleChangeTabBar : public QTabBar +{ + Q_OBJECT + + QTimer timer; + int count; + +public: + TitleChangeTabBar(QWidget * parent = 0) : QTabBar(parent), count(0) + { + setMovable(true); + addTab("0"); + connect(&timer, SIGNAL(timeout()), this, SLOT(updateTabText())); + timer.start(1); + } + +public slots: + void updateTabText() + { + count++; + setTabText(0, QString("%1").arg(count)); + } +}; + +void tst_QTabBar::changeTitleWhileDoubleClickingTab() +{ + TitleChangeTabBar bar; + QPoint tabPos = bar.tabRect(0).center(); + + for(int i=0; i < 10; i++) + QTest::mouseDClick(&bar, Qt::LeftButton, 0, tabPos); +} + QTEST_MAIN(tst_QTabBar) #include "tst_qtabbar.moc" -- cgit v0.12