[Development] QLogger questions and proposal

Lincoln Ramsay lincoln.ramsay at nokia.com
Tue Apr 24 01:57:10 CEST 2012


On 04/24/2012 04:47 AM, ext Mike Zraly wrote:
> First, what happens if QLogger is used inside a shared library, that
> library gets unloaded, and then settings are updated?
>
> From reading the code, it looks like once qCDebug is called inside the
> shared library the address of the associated QLoggingCategoryObject will
> be added to the global QLoggingPrivate's _registeredCategories data
> member. When the library is unloaded that address will no longer be
> valid.

Someone else mentioned this (or a similar problem) which prompted me to 
come up with this patch: https://codereview.qt-project.org/23817

The thing is, I don't know that this by itself is enough to solve your 
problem but it certainly works.

> If the settings are then updated that invalid address will be
> passed to QLoggingPrivate::updateCategory. That method will de-reference
> the invalid address and generate a segmentation fault.

So I guess for now, don't do that ;)

> Second, how can I use qCDebug with a QLoggingCategory object defined
> inside a class or function which takes the category name as an argument?

Oh, this is the same thing that patch is designed to support.

If you check out the QT_LOG_CATEGORY macro you can see that it just 
creates an object inside a namespace. With that patch you should be able 
to construct such objects wherever and whenever you feel like it and 
when they go away things will be cleaned up appropriately.

I know there was a suggestion at one point that we ditch that macro and 
just have concrete classes declared (and passed to qCDebug). If we do 
that, your use case becomes trivial to support.

> 1. Add a destructor to QLoggingCategory that removes it from
> QLoggingPrivate's _registeredCategories data member.

See the patch.

> 2. Get rid of the QT_LOG_CATEGORY macro and expose QLogging category
> directly.

Yeah... what I said before.

I think there is merit in this idea. We may have to be a little careful 
since people have already started using this code (ie. I'd like to keep 
source compatibility) but I think this is worth a try.


-- 
Lincoln Ramsay - Senior Software Engineer
Qt Development Frameworks, Nokia - http://qt.nokia.com/



More information about the Development mailing list