Problem with applications which have a system tray applet and secondary windows

Ingo Klöcker kloecker at
Mon Dec 8 22:16:53 GMT 2003

On Monday 08 December 2003 12:56, Martijn Klingens wrote:
> On Sun, 7 Dec 2003, Ingo [iso-8859-1] Klöcker wrote:
> > > Why not simply call kapp->ref() from the systemtray (your derived
> > > class for now, the base one in kde-4 maybe), and deref in the
> > > dtor?
> > >
> > > Then the user has to close the systray thingie by whichever way,
> > > before the process exits.
> >
> > Hah! I'm glad I'm not the only one that makes this mistake. That's
> > what I tried first after I found out about kapp->ref(). But it
> > doesn't work. Now, think again and tell me why it won't work. ;-)
> >
> > Hint: kapp->deref() is called each time a last visible window is
> > closed. And you can close a last visible window more than once.
> We had similar issues in Kopete, but there we solved it by not
> closing the main window at all and instead _hiding_ it.

That's exactly what we do in KMail. But KMainWindow::closeEvent() checks 
whether the window that is being closed is the last _visible_ (== 
non-hidden) window. Any _hidden_ windows will not be counted. The 
relevant code snippet:
        int not_withdrawn = 0;
        QPtrListIterator<KMainWindow> it(*KMainWindow::memberList);
        for (it.toFirst(); it.current(); ++it){
            if ( !it.current()->isHidden() && it.current()->isTopLevel() 
&& it.current() != this )
What you did is that you reimplemented KMainWindow::closeEvent() in 
KopeteChatWindow so that kapp->deref() isn't called anymore. But that 
won't help that much for KMail because in KMail a composer window might 
really be the last window (and not only the last visible window) but in 
Kopete a KopeteChatWindow can never exist without the KopeteWindow (may 
it be hidden or not).

Reimplementing KMainWindow::closeEvent() isn't really a good solution if 
one just wants to get rid of the kapp->deref() in certain situations. 
This just leads to bugs which are fixed in KMainWindow::closeEvent() 
but not in the duplicated code.

> What also may or may not help is fiddling with WDestructiveClose.
> IIRC the deref is used only for destructively closed windows.

This does only make sense for the main window (in order to dock/hide it 
into the system tray instead of deleting it). Secondary windows must be 
closed. kmainwindow.cpp doesn't contain any reference to 
Qt::WDestructiveClose except for a comment. So KMainWindow doesn't seem 
to care for this flag at all.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
URL: <>

More information about the kde-core-devel mailing list