A Qt replacement for KGlobal::ref and deref

Stephen Kelly steveire at gmail.com
Wed Feb 9 20:01:09 GMT 2011


KGLobal::ref and KGLobal::deref are used in KDE instead of 

The reason for this is that with the (de)ref solution

* KJobs which were not finished before the last window was closed will be 
completed before the app exits
* KRun completes its task before the app exits if the last window is closed.

KGlobal::ref and deref are the only internal KDE dependencies of KJob, so 
KJob would be a Qt only library if it didn't need them, and it could be used 
by Qt-only applications. I thought this was a small fry to try to proof-of-
concept the idea of more modularisation of functional libraries and less 
global or platformy dependencies in kdelibs.


I asked Thiago if I the patch would be applied if I wrote one for 
QCoreApplication to fill the role instead, so that we could do 
s/KGlobal::ref/qApp->ref/g in KDE, and QCoreApplication::ref and deref would 
fill the role that the KGlobal methods currently do, and QMainWindow (or 
maybe all top level QWidgets) would use them. 

Obviously there would need to be more thought into how it would react with 
setQuitOnLastWindowClosed etc, but it doesn't matter because Thiago said the 
patch would not be applied. The argument against it was that if the last 
window of a gui app is closed, the app should quit and any running jobs 
should be either completed by then or terminated before the last window is 
allowed to be closed. Thiago thought that ref/deref were a bad idea in the 
first place and shouldn't be in Qt. I disagree, but there you have it.

It's possible that I just didn't argue the case for a ref/deref solution in 
Qt well enough because I don't know all the use cases. It's not clear to me 
whether systray icons which outlive the last main window (and allow 
restoring it) and are managed by the application are affected by 

Thiago did also offer the solution of a separate service providing the 
refcounted quit functionality, but the problem with that is that all 
libraries and applications need to use the same ref/deref code otherwise it 
won't work. If I create a separate library with a service providing that 
functionality it wouldn't help because there would be no guarantee that all 
apps and libraries would use it. The solution would need to be in Qt. It 
works in KDE of course because all KDE libraries and applications use 
KGlobal::ref and deref, which perpetuates our walled garden.

So any other ideas on a replacement for KGlobal::ref and deref to make KJob 
a Qt only library by extending Qt some other way or otherwise?

All the best,


More information about the kde-core-devel mailing list