Skip to content

Commit

Permalink
Fix compilation of qCDebug("", ...) with QT_NO_DEBUG_OUTPUT
Browse files Browse the repository at this point in the history
... and fix QT_NO_INFO_OUTPUT, QT_NO_WARNING_OUTPUT alongside.

Fixes: QTBUG-74359
Change-Id: I2167dc943ae8c52602e08e24ca815d95f82a5db8
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
kkoehne committed Mar 14, 2019
1 parent b8d5e0b commit 097bf6f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
49 changes: 33 additions & 16 deletions src/corelib/io/qloggingcategory.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,30 @@ class Q_CORE_EXPORT QLoggingCategory
return category; \
}

#define qCDebug(category, ...) \
#if !defined(QT_NO_DEBUG_OUTPUT)
# define qCDebug(category, ...) \
for (bool qt_category_enabled = category().isDebugEnabled(); qt_category_enabled; qt_category_enabled = false) \
QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).debug(__VA_ARGS__)
#define qCInfo(category, ...) \
#else
# define qCDebug(category, ...) QT_NO_QDEBUG_MACRO()
#endif

#if !defined(QT_NO_INFO_OUTPUT)
# define qCInfo(category, ...) \
for (bool qt_category_enabled = category().isInfoEnabled(); qt_category_enabled; qt_category_enabled = false) \
QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).info(__VA_ARGS__)
#define qCWarning(category, ...) \
#else
# define qCInfo(category, ...) QT_NO_QDEBUG_MACRO()
#endif

#if !defined(QT_NO_WARNING_OUTPUT)
# define qCWarning(category, ...) \
for (bool qt_category_enabled = category().isWarningEnabled(); qt_category_enabled; qt_category_enabled = false) \
QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).warning(__VA_ARGS__)
#else
# define qCWarning(category, ...) QT_NO_QDEBUG_MACRO()
#endif

#define qCCritical(category, ...) \
for (bool qt_category_enabled = category().isCriticalEnabled(); qt_category_enabled; qt_category_enabled = false) \
QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).critical(__VA_ARGS__)
Expand All @@ -144,26 +159,28 @@ class Q_CORE_EXPORT QLoggingCategory
}

// check for enabled category inside QMessageLogger.
#define qCDebug qDebug
#define qCInfo qInfo
#define qCWarning qWarning
#define qCCritical qCritical

#endif // Q_COMPILER_VARIADIC_MACROS || defined(Q_MOC_RUN)

#if defined(QT_NO_DEBUG_OUTPUT)
# undef qCDebug
#if !defined(QT_NO_DEBUG_OUTPUT)
# define qCDebug qDebug
#else
# define qCDebug(category) QT_NO_QDEBUG_MACRO()
#endif
#if defined(QT_NO_INFO_OUTPUT)
# undef qCInfo

#if !defined(QT_NO_INFO_OUTPUT)
# define qCInfo qInfo
#else
# define qCInfo(category) QT_NO_QDEBUG_MACRO()
#endif
#if defined(QT_NO_WARNING_OUTPUT)
# undef qCWarning

#if !defined(QT_NO_WARNING_OUTPUT)
# define qCWarning qWarning
#else
# define qCWarning(category) QT_NO_QDEBUG_MACRO()
#endif

#define qCCritical qCritical

#endif // Q_COMPILER_VARIADIC_MACROS || defined(Q_MOC_RUN)

QT_END_NAMESPACE

#endif // QLOGGINGCATEGORY_H
1 change: 1 addition & 0 deletions tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void tst_QNoDebug::noDebugOutput() const
// should do nothing
qDebug() << "foo";
qCDebug(cat) << "foo";
qCDebug(cat, "foo");

// qWarning still works, though
QTest::ignoreMessage(QtWarningMsg, "bar");
Expand Down

0 comments on commit 097bf6f

Please sign in to comment.