QGuiApplication: do not emit deprecated signals

... when QT_DISABLE_DEPRECATED_BEFORE is past the deprecation version.

This commit actually stops using the deprecated signals when we build
Qt with QT_DISABLE_DEPRECATED_BEFORE >= 0x060000. Otherwise we will
get a compilation error because the signals will be removed.

Task-number: QTBUG-104857
Change-Id: Ie513ecc9451bf2d88f80857cf19f3d2b4958d022
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 68ea9c022701359b447be076888331a4f9d9085b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Ivan Solovev 2022-07-11 11:59:14 +02:00 committed by Qt Cherry-pick Bot
parent 3f46c4cb5d
commit 1ea89d761c
3 changed files with 24 additions and 0 deletions

View File

@ -3398,6 +3398,7 @@ QPalette QGuiApplicationPrivate::basePalette() const
void QGuiApplicationPrivate::handlePaletteChanged(const char *className)
{
#if QT_DEPRECATED_SINCE(6, 0)
if (!className) {
Q_ASSERT(app_pal);
QT_WARNING_PUSH
@ -3405,6 +3406,9 @@ QT_WARNING_DISABLE_DEPRECATED
emit qGuiApp->paletteChanged(*QGuiApplicationPrivate::app_pal);
QT_WARNING_POP
}
#else
Q_UNUSED(className);
#endif // QT_DEPRECATED_SINCE(6, 0)
if (is_app_running && !is_app_closing) {
QEvent event(QEvent::ApplicationPaletteChange);
@ -3463,10 +3467,14 @@ void QGuiApplication::setFont(const QFont &font)
if (emitChange && qGuiApp) {
auto font = *QGuiApplicationPrivate::app_font;
locker.unlock();
#if QT_DEPRECATED_SINCE(6, 0)
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
emit qGuiApp->fontChanged(font);
QT_WARNING_POP
#else
Q_UNUSED(font);
#endif // QT_DEPRECATED_SINCE(6, 0)
QEvent event(QEvent::ApplicationFontChange);
QGuiApplication::sendEvent(qGuiApp, &event);
}

View File

@ -520,26 +520,35 @@ void tst_QGuiApplication::palette()
// The default application palette is not resolved
QVERIFY(!QGuiApplication::palette().resolveMask());
// TODO: add event processing instead of the signal
#if QT_DEPRECATED_SINCE(6, 0)
QSignalSpy signalSpy(&app, SIGNAL(paletteChanged(QPalette)));
#endif
QPalette oldPalette = QGuiApplication::palette();
QPalette newPalette = QPalette(Qt::red);
QGuiApplication::setPalette(newPalette);
QVERIFY(palettesMatch(QGuiApplication::palette(), newPalette));
#if QT_DEPRECATED_SINCE(6, 0)
QCOMPARE(signalSpy.count(), 1);
#endif
QVERIFY(palettesMatch(signalSpy.at(0).at(0).value<QPalette>(), newPalette));
QCOMPARE(QGuiApplication::palette(), QPalette());
QGuiApplication::setPalette(oldPalette);
QVERIFY(palettesMatch(QGuiApplication::palette(), oldPalette));
#if QT_DEPRECATED_SINCE(6, 0)
QCOMPARE(signalSpy.count(), 2);
#endif
QVERIFY(palettesMatch(signalSpy.at(1).at(0).value<QPalette>(), oldPalette));
QCOMPARE(QGuiApplication::palette(), QPalette());
QGuiApplication::setPalette(oldPalette);
QVERIFY(palettesMatch(QGuiApplication::palette(), oldPalette));
#if QT_DEPRECATED_SINCE(6, 0)
QCOMPARE(signalSpy.count(), 2);
#endif
QCOMPARE(QGuiApplication::palette(), QPalette());
}

View File

@ -215,10 +215,12 @@ void tst_QApplication::staticSetup()
EventWatcher()
{
qApp->installEventFilter(this);
#if QT_DEPRECATED_SINCE(6, 0)
QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED
QObject::connect(qApp, &QApplication::paletteChanged, [&]{ ++palette_changed; });
QObject::connect(qApp, &QApplication::fontChanged, [&]{ ++font_changed; });
QT_WARNING_POP
#endif
}
protected:
@ -248,8 +250,13 @@ QT_WARNING_POP
font.setBold(!font.bold());
qApp->setFont(font);
QApplication::processEvents();
#if QT_DEPRECATED_SINCE(6, 0)
QCOMPARE(watcher.palette_changed, 2);
QCOMPARE(watcher.font_changed, 2);
#else
QCOMPARE(watcher.palette_changed, 1);
QCOMPARE(watcher.font_changed, 1);
#endif
}