[Development] Difficulties using Qt's new categorized logging. How to install filters?

Mark markg85 at gmail.com
Sat Oct 12 15:41:10 CEST 2013


Hi,

I just tried fiddling with the new Qt categorized logging and am hitting
some difficulties. I've read the documentation [1] and had a discussion on
irc (Qt-Labs) about how to install a global filter.

The documentation states:
// in a header
Q_DECLARE_LOGGING_CATEGORY(QT_DRIVER_USB)

// in one source file
Q_LOGGING_CATEGORY(QT_DRIVER_USB, "qt.driver.usb")

// usbEntries() will only be called if QT_DRIVER_USB category is enabled
qCDebug(QT_DRIVER_USB) << "devices: " << usbEntries();

So the above line will only log when QT_DRIVER_USB is enabled. How do i
enable it? It's a new category "qt.driver.usb" so by that logic i'm
inclined to think that i need to install a new filter for this category and
enable debugging in there. That would be something like this:

QLoggingCategory usbCategory("qt.driver.usb");
usbCategory.setEnabled(QtDebugMsg, true);

Now if i do:
qCDebug(usbCategory) << "some logging";

Then it works as expected. But that's not what i want and not global. How
can i get the initial example to work - with QT_DRIVER_USB?

I think it would be a good idea to update the documentation with this
information as well. I tried following the testcase, but that didn't help
me much in getting this working either.

Kind regards,
Mark

[1] http://doc-snapshot.qt-project.org/qt5-stable/qloggingcategory.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20131012/6a0a48a6/attachment.html>


More information about the Development mailing list