Results 1 to 5 of 5

Thread: Setting QApplications "main widget" for exec()

  1. #1
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Setting QApplications "main widget" for exec()

    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?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Setting QApplications "main widget" for exec()

    Check the System Tray Icon Example. It catches close event and hides the window instead of closing it:
    Qt Code:
    1. void Window::closeEvent(QCloseEvent *event)
    2. {
    3. if (trayIcon->isVisible()) {
    4. ...
    5. hide();
    6. event->ignore();
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Aug 2006
    Posts
    90
    Thanks
    6
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting QApplications "main widget" for exec()

    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.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Setting QApplications "main widget" for exec()

    J-P Nurmi

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

    Default Re: Setting QApplications "main widget" for exec()

    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.

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.