From cd5d8313583e002742b9b00988c2011e8eaa923c Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Fri, 17 Apr 2009 15:27:49 +0200 Subject: Possible assert when hiding tabbed QDockWidget The problem is in QTabBar which emits the currentChanged signal before accessing its own internal data. As we react to that signal by possibly removing/adding tabs, it can cause a assertion failure. Task-number: 251184 Reviewed-by: ogoffart --- src/gui/widgets/qtabbar.cpp | 6 +++--- tests/auto/qtabbar/tst_qtabbar.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/gui/widgets/qtabbar.cpp b/src/gui/widgets/qtabbar.cpp index b6e6b6d..b562b1f 100644 --- a/src/gui/widgets/qtabbar.cpp +++ b/src/gui/widgets/qtabbar.cpp @@ -1167,13 +1167,13 @@ void QTabBar::setCurrentIndex(int index) d->currentIndex = index; update(); d->makeVisible(index); + d->tabList[index].lastTab = oldIndex; + d->layoutWidgets(oldIndex); + d->layoutWidgets(index); #ifdef QT3_SUPPORT emit selected(index); #endif emit currentChanged(index); - d->tabList[index].lastTab = oldIndex; - d->layoutWidgets(oldIndex); - d->layoutWidgets(index); } } diff --git a/tests/auto/qtabbar/tst_qtabbar.cpp b/tests/auto/qtabbar/tst_qtabbar.cpp index 433eb86..31722de 100644 --- a/tests/auto/qtabbar/tst_qtabbar.cpp +++ b/tests/auto/qtabbar/tst_qtabbar.cpp @@ -92,6 +92,8 @@ private slots: void moveTab_data(); void moveTab(); + + void task251184_removeTab(); }; // Testing get/set functions @@ -503,5 +505,35 @@ void tst_QTabBar::moveTab() bar.callMoveTab(from, to); } + +class MyTabBar : public QTabBar +{ + Q_OBJECT +public slots: + void onCurrentChanged() + { + //we just want this to be done once + disconnect(this, SIGNAL(currentChanged(int)), this, SLOT(onCurrentChanged())); + removeTab(0); + } +}; + +void tst_QTabBar::task251184_removeTab() +{ + MyTabBar bar; + bar.addTab("bar1"); + bar.addTab("bar2"); + QCOMPARE(bar.count(), 2); + QCOMPARE(bar.currentIndex(), 0); + + bar.connect(&bar, SIGNAL(currentChanged(int)), SLOT(onCurrentChanged())); + bar.setCurrentIndex(1); + + QCOMPARE(bar.count(), 1); + QCOMPARE(bar.currentIndex(), 0); + QCOMPARE(bar.tabText(bar.currentIndex()), QString("bar2")); +} + + QTEST_MAIN(tst_QTabBar) #include "tst_qtabbar.moc" -- cgit v0.12