Results 1 to 6 of 6

Thread: system tray problem

  1. #1
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default system tray problem

    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:

    Qt Code:
    1. void mainwindow:: minimizetotraySlot()
    2. {
    3. if (isHidden())
    4. {
    5. show();
    6. trayIcon->hide();
    7. }
    8. else
    9. {
    10. hide();
    11. trayIcon->show();
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 


    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.
    Last edited by vvdounai; 14th November 2007 at 05:04.

  2. #2
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: system tray problem

    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 :

    Qt Code:
    1. void Knewz::closeEvent( QCloseEvent *event )
    2. {
    3. if( ok_to_close ){
    4. queryExit();
    5. event->accept();
    6. }else{
    7. event->ignore();
    8. hide();
    9. }
    10. }
    11.  
    12. void Knewz::shutdown()
    13. {
    14. ok_to_close = true;
    15. close();
    16. }
    To copy to clipboard, switch view to plain text mode 
    shutdown() is only called from an action in the menu, nowhere else.

  3. The following user says thank you to Valheru for this useful post:

    vvdounai (14th November 2007)

  4. #3
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: system tray problem

    Qt closes application when last top level window is closed by default
    Qt Code:
    1. void QApplication::setQuitOnLastWindowClosed ( bool quit )
    To copy to clipboard, switch view to plain text mode 
    maybe this is related(all in all, when application is in tray, all windows are closed).

  5. #4
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: system tray problem

    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.
    Last edited by vvdounai; 14th November 2007 at 08:51.

  6. #5
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: system tray problem

    hi again,
    If you turned off automatic application termination feature of qt, you shall terminate it on your own.
    Qt Code:
    1. connect(qApp,
    2. SIGNAL(lastWindowClosed(void)),
    3. this,
    4. SLOT(closeIfNoTryIcon(void)));
    5.  
    6. *::closeIfNoTryIcon(void)
    7. {
    8. if(/*there's no try icon shown*/)
    9. qApp->quit()
    10. }
    To copy to clipboard, switch view to plain text mode 
    If you turned off automatic application termination feature of qt, you shall terminate it on your own.

  7. The following user says thank you to mchara for this useful post:

    vvdounai (14th November 2007)

  8. #6
    Join Date
    Nov 2007
    Posts
    7
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: system tray problem

    Ok, I got it. As mchara said, I choose to add qApp->quit(); as the last line of colseEvent() to close the application.

    thanks

Similar Threads

  1. Minimize to system tray
    By aLiNuSh in forum Newbie
    Replies: 17
    Last Post: 4th March 2010, 13:51
  2. Minimize to system tray
    By krivenok in forum Qt Programming
    Replies: 5
    Last Post: 13th January 2009, 05:34
  3. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 14:15
  4. Replies: 16
    Last Post: 7th March 2006, 16:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.