K_GLOBAL_STATIC and other macros

Matthias Kretz kretz at kde.org
Fri Apr 13 11:30:49 BST 2007


On Friday 13 April 2007 12:09, Thiago Macieira wrote:
> K_GLOBAL_STATIC objects can also be registered for ~QCoreApplication-time
> destruction, whereas Q_GLOBAL_STATIC ones are destroyed only on unload.
> For that reason, you also have name.isDestroyed() (note the ., not ->) in
> K_GLOBAL_STATIC.

While we're at it here's a rule to be safe on destruction:
  If you use any Qt (or even KDE) class/function in the destructor of the
  global static you have to destroy the object in a Qt post routine.
Rationale:
  The Qt (or KDE) function might depend on another global static object and
  since the objects are destroyed in the reverse order in which they were
  constructed you might get crashes. Making sure that the Qt/KDE functions
  don't depend on any global static only helps you for that specific version
  of Qt/KDE. E.g. from Qt 4.2 -> 4.3 QTemporaryFile became unsafe to use in a
  destructor of a global object.

For that reason I think we should let K_GLOBAL_STATIC objects default to 
destruction in a Qt post routine. If you know what you're doing you can still 
call qRemovePostRoutine(globalObject.destroy).

-- 
________________________________________________________
Matthias Kretz (Germany)                            <><
http://Vir.homelinux.org/
MatthiasKretz at gmx.net, kretz at kde.org,
Matthias.Kretz at urz.uni-heidelberg.de




More information about the kde-core-devel mailing list