diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-04-17 15:27:49 +0200 |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-04-17 15:31:52 +0200 |
commit | cd5d8313583e002742b9b00988c2011e8eaa923c (patch) | |
tree | cb4eb59e5b9529a11b01de20177da389c25452c6 | |
parent | 7c815bc2d4ea922d75f49f7dc29c81362ce5210e (diff) |
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
-rw-r--r-- | src/gui/widgets/qtabbar.cpp | 6 | ||||
-rw-r--r-- | 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 b6e6b6dc29..b562b1fb28 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 433eb86aa9..31722de73b 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" |