From b8a38a6737acd670d92197ca5b009590d9fd8a9c Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 9 Jan 2014 15:38:17 +0100 Subject: Allow printf style for qCDebug, qCWarning, qCCritical macros Add support for using qCDebug and friends in the 'printf style' way. This allows an almost mechanical conversion of existing qDebug, qWarning, qCritical macros, and allows avoiding the size overhead the streaming style incurs (mostly due to inlined QDebug code). To handle this gracefully we require variadic macros (part of C++11/C99). For compilers not supporting variadic macros we fall back to checking the category in QMessageLogger. [ChangeLog][QtCore][Logging] Allow qCDebug macros to be used in a printf style. Change-Id: I5a8fb135dca504e1d621bb67bf4b2a50c73d41b9 Reviewed-by: Thiago Macieira --- src/corelib/doc/snippets/code/qlogging/qlogging.cpp | 4 ++++ src/corelib/doc/snippets/qloggingcategory/main.cpp | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'src/corelib/doc') diff --git a/src/corelib/doc/snippets/code/qlogging/qlogging.cpp b/src/corelib/doc/snippets/code/qlogging/qlogging.cpp index 774610a3c0..d3b9e1fd14 100644 --- a/src/corelib/doc/snippets/code/qlogging/qlogging.cpp +++ b/src/corelib/doc/snippets/code/qlogging/qlogging.cpp @@ -52,3 +52,7 @@ } } //! [1] + +//! [2] + QLoggingCategory &category(); +//! [2] diff --git a/src/corelib/doc/snippets/qloggingcategory/main.cpp b/src/corelib/doc/snippets/qloggingcategory/main.cpp index c1dad7f43a..628243dbdd 100644 --- a/src/corelib/doc/snippets/qloggingcategory/main.cpp +++ b/src/corelib/doc/snippets/qloggingcategory/main.cpp @@ -128,6 +128,27 @@ oldCategoryFilter = QLoggingCategory::installFilter(myCategoryFilter); //![12] } + { +//![13] + QLoggingCategory category("qt.driver.usb"); + qCDebug(category, "a debug message logged into category %s", category.categoryName()); +//![13] + } + + { +//![14] + QLoggingCategory category("qt.driver.usb"); + qCWarning(category, "a warning message logged into category %s", category.categoryName()); +//![14] + } + + { +//![15] + QLoggingCategory category("qt.driver.usb"); + qCCritical(category, "a critical message logged into category %s", category.categoryName()); +//![15] + } + return 0; } -- cgit v1.2.3