From 2d63f8fe5b77747014e1c5807c9d457611bd9304 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 11 Nov 2009 17:30:54 +0100 Subject: Fixed: QFontComboBox emits the currentFontChanged() signal twice Task-number: QTBUG-2438 Reviewed-by: Thierry --- src/gui/widgets/qfontcombobox.cpp | 4 +++- tests/auto/qfontcombobox/tst_qfontcombobox.cpp | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/qfontcombobox.cpp b/src/gui/widgets/qfontcombobox.cpp index a66657d..d601f81 100644 --- a/src/gui/widgets/qfontcombobox.cpp +++ b/src/gui/widgets/qfontcombobox.cpp @@ -427,8 +427,10 @@ void QFontComboBox::setCurrentFont(const QFont &font) Q_D(QFontComboBox); if (font != d->currentFont) { d->currentFont = font; - emit currentFontChanged(d->currentFont); d->_q_updateModel(); + if (d->currentFont == font) { //else the signal has already be emitted by _q_updateModel + emit currentFontChanged(d->currentFont); + } } } diff --git a/tests/auto/qfontcombobox/tst_qfontcombobox.cpp b/tests/auto/qfontcombobox/tst_qfontcombobox.cpp index 7045c19..b974ecab 100644 --- a/tests/auto/qfontcombobox/tst_qfontcombobox.cpp +++ b/tests/auto/qfontcombobox/tst_qfontcombobox.cpp @@ -153,7 +153,7 @@ void tst_QFontComboBox::currentFont() if (oldCurrentFont != box.currentFont()) { //the signal may be emit twice if there is a foundry into brackets - QVERIFY(spy0.count() >= 1); + QCOMPARE(spy0.count(),1); } } @@ -286,6 +286,10 @@ void tst_QFontComboBox::currentFontChanged() if (box.model()->rowCount() > 2) { QTest::keyPress(&box, Qt::Key_Down); QCOMPARE(spy0.count(), 1); + + QFont f( "Sans Serif" ); + box.setCurrentFont(f); + QCOMPARE(spy0.count(), 2); } else qWarning("Not enough fonts installed on test system. Consider adding some"); } -- cgit v0.12