PDA

View Full Version : system tray problem



vvdounai
14th November 2007, 03:51
hello, everyone!

I designed a program, I use F12 to invoke its minimize to try action. And the user can restore the window with tray icon menu.

I use a slot function as follows:



void mainwindow:: minimizetotraySlot()
{
if (isHidden())
{
show();
trayIcon->hide();
}
else
{
hide();
trayIcon->show();
}
}



And I define a tray icon menu as

restore, quit, about.

however, when I select the about item in the tray icon menu, after the about dialog displayed, the application will quit. I don't know why? The about dialog is only a common MessageBox.

Valheru
14th November 2007, 06:28
I have the exact same problem. I am using KDE4, but no matter what option I choose from the tray menu, even if I hit cancel it will also shut down the entire application. I would like to know what causes this.

Are you overriding closeEvent by any chance? I thought maybe it was this that was causing my app to do this, although I fail to see how given teh code :


void Knewz::closeEvent( QCloseEvent *event )
{
if( ok_to_close ){
queryExit();
event->accept();
}else{
event->ignore();
hide();
}
}

void Knewz::shutdown()
{
ok_to_close = true;
close();
}shutdown() is only called from an action in the menu, nowhere else.

mchara
14th November 2007, 06:47
Qt closes application when last top level window is closed by default


void QApplication::setQuitOnLastWindowClosed ( bool quit )

maybe this is related(all in all, when application is in tray, all windows are closed).

vvdounai
14th November 2007, 07:47
I set the function as mchara says in his post. It can avoid the above problems. However, I cann't close the application now! :(

So can someone provide another solution? thanks.


btw: I found a solution that we can add qApp->quit(); as the last line of colseEvent() to close the application now. but I don't know if it is a good method.

mchara
14th November 2007, 07:54
hi again,
If you turned off automatic application termination feature of qt, you shall terminate it on your own.


connect(qApp,
SIGNAL(lastWindowClosed(void)),
this,
SLOT(closeIfNoTryIcon(void)));

*::closeIfNoTryIcon(void)
{
if(/*there's no try icon shown*/)
qApp->quit()
}

If you turned off automatic application termination feature of qt, you shall terminate it on your own.

vvdounai
14th November 2007, 08:25
Ok, I got it. As mchara said, I choose to add qApp->quit(); as the last line of colseEvent() to close the application.

thanks:)