Can Q_GLOBAL_STATIC replace KStaticDelete ?

Thiago Macieira thiago at kde.org
Tue Jan 9 19:31:04 GMT 2007


Matthias Kretz wrote:
>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?

Yes: by defining the order in which they are constructed.

Normally, they should be destructed in the reverse order they were 
created, which may be different from the library unload order.

My local tests resulted in this:
TheObj::TheObj(so3)
TheObj::TheObj(so1)
TheObj::TheObj(so2)
TheObj::TheObj(main)
main
TheObj::TheObj(global static so2)
TheObj::TheObj(global static so1)
TheObj::~TheObj(global static so1)
TheObj::~TheObj(global static so2)
TheObj::~TheObj(main)
TheObj::~TheObj(so2)
TheObj::~TheObj(so1)
TheObj::~TheObj(so3)

where TheObj is an object that prints the message when constructed and 
when destructed.

so1, so2 and so3 are libraries; so1 and so2 both depend on so3; main is 
the program and it depends on so2 and so1 (in that order). The 
two "global static" are Q_GLOBAL_STATIC; the other ones are real statics 
(as can be seen from the fact that they were constructed before main()).

This result may be non-portable.

>> 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.

I know. Doesn't make it less ugly, though.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070109/0c68379d/attachment.sig>


More information about the kde-core-devel mailing list