Can Q_GLOBAL_STATIC replace KStaticDelete ?

Matthias Kretz kretz at
Tue Jan 9 08:55:20 GMT 2007

On Tuesday 09 January 2007 09:08, Thiago Macieira wrote:
> Matthias Kretz wrote:
> >With QCoreApplication gone the main thread cannot postEvents to the
> > other thread anymore, which is needed to cleanly exit the thread.
> This sounds like a Qt bug. You should be able to post events to other,
> still running threads. In fact, you should be able to post events even
> from non-QThread threads.

Apparently the Q_GLOBAL_STATIC allObjects was destructed before the postEvent 
was called. And with allObjects gone postEvent refuses to work.

> What you can't do is post events after the global static destructors have
> run, when the internal Qt event and object locks are gone.

Exactly, I have a global static that needs to be destructed before Qt's 
globals. :-/ There's no way to define destruction order for statics, no?

~QCoreApplication also calls QThread::cleanup(). Dunno whether that will hurt 
thread communication, but it looks dangerous enough.

> >Using Solid a similar warning appeared:
> >QObject::startTimer: QTimer can only be used with threads started with
> > QThread
> >
> >The reason is that KLibrary wants to start a QTimer when the factory
> > object is destroyed. (I committed a fix that checks for the presence of
> >QCoreApplication::instance(), so that this warning is gone by now.)
> This sounds like a KLibrary bug instead. The timer would never be run, so
> a new solution must be found.

See attached kde-commits email. I think it's the needed bugfix, but I'm not 
100% sure that it's safe to call "delete this" in the slot.

> From the other email:
> >On Monday 08 January 2007 19:56, Thiago Macieira wrote:
> >> What happens to those objects if the application exits without
> >> QCoreApplication's destructor running?
> >
> >Forgot to answer this one... They are deleted by KStaticDeleter. But
> >QCoreApplication has to be present for the destructors to work
> > correctly.
> I don't think it's a good idea to call an object from inside its
> destructor. In this case, we're at least reasonably sure that the
> callbacks are run very early...

You mean QCoreApplication being called through a postRoutine? It's not nice, 
but it's the same we've been doing all the time from ~KApplication.

Matthias Kretz (Germany)                            <><
MatthiasKretz at, kretz at,
Matthias.Kretz at
-------------- next part --------------
An embedded message was scrubbed...
From: Matthias Kretz <kretz at>
Subject: KDE/kdelibs/kdecore
Date: Mon, 08 Jan 2007 16:37:26 +0000
Size: 4302
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <>

More information about the kde-core-devel mailing list