KInstance redesign

Matthias Kretz kretz at
Fri Jan 19 12:15:30 GMT 2007


after Thiago suggested to fix the static destruction issue by refcounting 
KInstance to keep it until everything that needs it is gone, I started to 
wonder if we want to keep KInstance the way it is now or whether we may dare 
to change it completely. (LXR says 1683 references in 826 files... so much 
for porting efforts)

First I think it's hard to understand what KInstance actually is supposed to 
do. Perhaps the first step would be to define what it's used for and then 
give it a better name. Here's how I understand it:
- without components KInstance is not needed; it could be replaced by KGlobal
- but components want some pseudo-global data, different from the host 
- also in an application there is always only one active component which can 
be identified using KGlobal::activeInstance

name suggestion: KComponentData (i00:13:02:0F:56:37t's basically a collection 
of KStandardDirs, KConfig and KAboutData objects that should be different per 
component). KGlobal then would provide the methods mainComponent and 
activeComponent instead of instance and activeInstance.

Suggestions for the API:
- The objects should be passed by value, so that it can easily keep a refcount 
(using QAtomic) of the internal data.
- The ctor that takes (const QByteArray &instanceName) could look at the 
current objects whether one with that name exists and return that one (that 
means you can identify a component using either the instanceName or the 
KInstance/KComponentData object).

- KApplication does not inherit KInstance anymore but provides convenience 
functions that forward the calls to the mainComponent object

Do you think this is a good idea? Shall I go ahead and write a first patch and 
if you like it create a work branch?

Matthias Kretz (Germany)                            <><
MatthiasKretz at, kretz at,
Matthias.Kretz at
-------------- 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