PDA

View Full Version : Setting QApplications "main widget" for exec()



bpetty
18th September 2007, 17:34
Hey guys,

I am noticing something very odd when using a systray icon. My systray icon, when a menu item gets clicked, triggers an action found in my Main Window class that opens a dialog. When the dialog closes qApp->exec() returns!!! I read the doc on QApplication::exec() and it says:


Enters the main event loop and waits until exit() is called or the main widget is destroyed

My "main widget" is my Main Window class that inherits from QMainWindow... but it is thinking it is my dialog! Is there a way to tell it what my main widget is?

jpn
18th September 2007, 17:51
Check the System Tray Icon Example (http://doc.trolltech.com/4.3/desktop-systray.html). It catches close event and hides the window instead of closing it:


void Window::closeEvent(QCloseEvent *event)
{
if (trayIcon->isVisible()) {
...
hide();
event->ignore();
}
}

bpetty
18th September 2007, 18:18
That is not the problem. I should have described it better...

My application is already in the systray.
I have a qmenu that it uses whose QActions are tied into my Main Window class.
One of these actions calls a method that opens a QDialog.
When the dialog closes and the method return... my QApplication quits even though I have a systrayicon and my Main Window is hidden.
When I trigger the same QAction from my Main Window directly, it does no close my QApp.

jpn
18th September 2007, 18:26
Oh, have you tried QApplication::setQuitOnLastWindowClosed(false) (http://doc.trolltech.com/4.3/qapplication.html#quitOnLastWindowClosed-prop) and/or QWidget::setAttribute(Qt::WA_QuitOnClose, false) for the dialog?

bpetty
18th September 2007, 19:49
Thanks J-P, that is why I am posting in the newb section :)
I read the reference... but didn't look at the "See also" section... :(

I'll have to repay everyone for taking the time to help me out some time.
Next time there is a Qt Programming Contest I'll submit a few things that should be really awesome. Since I am commercial I'll have to get it approved though. I don't want to say anything bad about the contributed code for the contest... err, I'll stop there. I'll try to submit some cool stuff next time it comes around.