From e27d14bd5584b942d22900412609b52c5c4bccd5 Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Thu, 17 Aug 2023 14:51:01 +0200 Subject: [PATCH] tst_QDockWidget: Fix compiler warning in non-development build Static variables for a message handler were used only in developer build, while they were declared unconditionally. That has lead to compiler warnings about unused variables in a non developer build. => declare them only in developer build => move assignment and static method in front of the method, that uses them. Change-Id: Ie06f91f7857130f08fd484a6e7319ddfd16c546b Reviewed-by: Volker Hilsheimer (cherry picked from commit 366b4d3ae7783a055a6b1d6fe18470169cb6f8f3) Reviewed-by: Qt Cherry-pick Bot --- .../widgets/qdockwidget/tst_qdockwidget.cpp | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp index 0de5fadfc53..61f8bf995bc 100644 --- a/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/widgets/widgets/qdockwidget/tst_qdockwidget.cpp @@ -104,10 +104,12 @@ private: // move a dock widget void moveDockWidget(QDockWidget* dw, QPoint to, QPoint from = QPoint()) const; +#ifdef QT_BUILD_INTERNAL // Message handling for xcb error QTBUG 82059 static void xcbMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg); public: bool xcbError = false; +#endif private: #ifdef QT_DEBUG @@ -128,11 +130,6 @@ private: }; -// Statics for xcb error / msg handler -static tst_QDockWidget *qThis = nullptr; -static void (*oldMessageHandler)(QtMsgType, const QMessageLogContext&, const QString&); -#define QXCBVERIFY(cond) do { if (xcbError) QSKIP("Test skipped due to XCB error"); QVERIFY(cond); } while (0) - // Testing get/set functions void tst_QDockWidget::getSetCheck() { @@ -1307,20 +1304,6 @@ bool tst_QDockWidget::checkFloatingTabs(QMainWindow* mainWindow, QPointerxcbError = true; - } - - return oldMessageHandler(type, context, msg); -} - #endif // QT_BUILD_INTERNAL // test floating tabs and item_tree consistency @@ -1450,6 +1433,27 @@ void tst_QDockWidget::floatingTabs() #endif // QT_BUILD_INTERNAL } +#ifdef QT_BUILD_INTERNAL +// Statics for xcb error / msg handler +static tst_QDockWidget *qThis = nullptr; +static void (*oldMessageHandler)(QtMsgType, const QMessageLogContext&, const QString&); +#define QXCBVERIFY(cond) do { if (xcbError) QSKIP("Test skipped due to XCB error"); QVERIFY(cond); } while (0) + +// detect xcb error +// qt.qpa.xcb: internal error: void QXcbWindow::setNetWmStateOnUnmappedWindow() called on mapped window +void tst_QDockWidget::xcbMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + Q_ASSERT(oldMessageHandler); + + if (type == QtWarningMsg && QString(context.category) == "qt.qpa.xcb" && msg.contains("internal error")) { + Q_ASSERT(qThis); + qThis->xcbError = true; + } + + return oldMessageHandler(type, context, msg); +} +#endif // QT_BUILD_INTERNAL + // test hide & show void tst_QDockWidget::hideAndShow() {