program exit itself when create dialog with QSystemTrayIcon
Hi,
I'm using QT creator in WINDOWS7
My program will exit itself when my MainWindow is hidden and I closed the messagebox created by the system tray icon.
main.cpp
Code:
int main(int argc, char* argv[]){
MainWindow *dialog = new MainWindow;
return app.exec();
}
mainwindow.h
Code:
MainWindow
::MainWindow(QWidget *parent
) :{
setupUi(this);
createActions();
createTrayIcon();
trayIcon->show();
showMessage();
}
void MainWindow::createActions(){
aboutAction
= new QAction(tr
("&About"),
this);
connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAbout()));
quitAction
= new QAction(tr
("&Quit"),
this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void MainWindow::createTrayIcon(){
trayIconMenu
= new QMenu(this);
trayIconMenu->addAction(aboutAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon->setContextMenu(trayIconMenu);
}
void MainWindow::showAbout(){
}
...
My program is designed not to have the mainwindow.
Every time I pressed "OK" or "X" on the about dialog, my program exited(with code 0.)
But I want my program to keep running in the background.
Thanks for help,
Jimmy
Re: program exit itself when create dialog with QSystemTrayIcon
Hi Jimmy,
Try the following:
Code:
int main(int argc, char* argv[]){
MainWindow *dialog = new MainWindow;
return app.exec();
}
Re: program exit itself when create dialog with QSystemTrayIcon
Thanks for this reply, but if you only add this, then your app doesn't exits at all!
You have to add QApplication::setQuitOnLastWindowClosed(1); at the CloseEvent :)
Anyway thx for the reply, very helpful!;)