diff options
Diffstat (limited to 'src/corelib/doc/snippets/qloggingcategory')
-rw-r--r-- | src/corelib/doc/snippets/qloggingcategory/main.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/corelib/doc/snippets/qloggingcategory/main.cpp b/src/corelib/doc/snippets/qloggingcategory/main.cpp index f5c47b2ae8..237ba5437e 100644 --- a/src/corelib/doc/snippets/qloggingcategory/main.cpp +++ b/src/corelib/doc/snippets/qloggingcategory/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the documentation of the Qt Toolkit. @@ -86,15 +86,20 @@ void myCategoryFilter(QLoggingCategory *); //![20] //![21] -QLoggingCategory::CategoryFilter oldCategoryFilter; +static QLoggingCategory::CategoryFilter oldCategoryFilter = nullptr; void myCategoryFilter(QLoggingCategory *category) { - // configure driver.usb category here, otherwise forward to to default filter. + // For a category set up after this filter is installed, we first set it up + // with the old filter. This ensures that any driver.usb logging configured + // by the user is kept, aside from the one level we override; and any new + // categories we're not interested in get configured by the old filter. + if (oldCategoryFilter) + oldCategoryFilter(category); + + // Tweak driver.usb's logging, over-riding the default filter: if (qstrcmp(category->categoryName(), "driver.usb") == 0) category->setEnabled(QtDebugMsg, true); - else - oldCategoryFilter(category); } //![21] @@ -107,8 +112,6 @@ int main(int argc, char *argv[]) //![2] //![22] - -// ... oldCategoryFilter = QLoggingCategory::installFilter(myCategoryFilter); //![22] |