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
Qt Code:
  1. int main(int argc, char* argv[]){
  2. QApplication app(argc, argv);
  3.  
  4. MainWindow *dialog = new MainWindow;
  5.  
  6. return app.exec();
  7. }
To copy to clipboard, switch view to plain text mode 

mainwindow.h
Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent)
  3. {
  4. setupUi(this);
  5.  
  6. createActions();
  7. createTrayIcon();
  8.  
  9. connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
  10.  
  11. trayIcon->show();
  12.  
  13. showMessage();
  14.  
  15. }
  16.  
  17. void MainWindow::createActions(){
  18. aboutAction = new QAction(tr("&About"), this);
  19. connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAbout()));
  20.  
  21. quitAction = new QAction(tr("&Quit"), this);
  22. connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
  23. }
  24.  
  25. void MainWindow::createTrayIcon(){
  26. trayIconMenu = new QMenu(this);
  27. trayIconMenu->addAction(aboutAction);
  28. trayIconMenu->addSeparator();
  29. trayIconMenu->addAction(quitAction);
  30.  
  31. trayIcon = new QSystemTrayIcon(this);
  32. trayIcon->setContextMenu(trayIconMenu);
  33. }
  34.  
  35. void MainWindow::showAbout(){
  36. QMessageBox::about(this, tr("Foo"), tr("Bar"));
  37. }
  38.  
  39. ...
To copy to clipboard, switch view to plain text mode 

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