Results 1 to 6 of 6

Thread: QSystemTrayIcon as "main window" design issue

  1. #1
    Join Date
    Nov 2007
    Posts
    53
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QSystemTrayIcon as "main window" design issue

    Hi,

    I am designing an application that open instances of a QMainWindow subclass when I double-clicked on a system tray icon.

    I've choosen to instanciate my QSystemTrayIcon subclass as the main widget in main.cpp so there is no parent widget for the QSystemTrayIcon and for QMainWindow subclasses as well as I can't set a QObject as a parent of a QMainWindow.

    The problem is I have a QAction in my QSystemTrayIcon subclass that I would like to enable or disable regarding a connexion state that is set in a deeper child level widget in a QThread.

    I have tried to define a static signal in the QThread subclass and connecting the QSystemTrayIcon directly to the class but it doesn't work and a search on the forum told me it is not possible as well.

    Sure, I have an idea how I can do it by creating a static method in the QSystemTrayIcon to notify connection / disconnection.

    But such a solution would make the QThread subclass specifically related to my application because I need to call QSystemTrayIcon::notifyConnection() in it.

    I have no need to use this QThread subclass elsewhere but I don't like to have such an architectural flaw in my app.

    Does someone skilled than me see an elegant solution to this problem ?

    Or is setting a QSystemTrayIcon as the main widget of an application is simply a very bad idea ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSystemTrayIcon as "main window" design issue

    Quote Originally Posted by nooky59 View Post
    I have tried to define a static signal in the QThread subclass and connecting the QSystemTrayIcon directly to the class but it doesn't work and a search on the forum told me it is not possible as well.
    There is no such thing as a static signal, but you can define normal signal.

  3. #3
    Join Date
    Nov 2007
    Posts
    53
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSystemTrayIcon as "main window" design issue

    Thanks for your answer.

    The problem is the QSystemTrayIcon can't access directly to each QThread instance so I can't connect it directly to the signal. This is why I thought a static signal could have solve the problem if it was possible.

    Finally, I have the solution. I will connect the QSystemTrayIcon to a signal in each QMainWindow created from the QSystemTrayIcon even if I don't keep a pointer to it (auto destruction with Qt::WA_DeleteOnClose).

    Then, I will connect each QMainWindow to a signal from its own thread.

    As there is only 2 levels depth to bring the signal to the QSystemTrayIcon, the architecture isn't so bad ;o)

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSystemTrayIcon as "main window" design issue

    Quote Originally Posted by nooky59 View Post
    Finally, I have the solution. I will connect the QSystemTrayIcon to a signal in each QMainWindow created from the QSystemTrayIcon even if I don't keep a pointer to it (auto destruction with Qt::WA_DeleteOnClose).

    Then, I will connect each QMainWindow to a signal from its own thread.
    You can connect a signal to a signal to avoid extra slot.

    Quote Originally Posted by nooky59 View Post
    As there is only 2 levels depth to bring the signal to the QSystemTrayIcon, the architecture isn't so bad ;o)
    Clean interfaces are far more important that an extra call. The user won't even notice it.

  5. #5
    Join Date
    Nov 2007
    Posts
    53
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSystemTrayIcon as "main window" design issue

    Quote Originally Posted by jacek View Post
    You can connect a signal to a signal to avoid extra slot.
    Yes, I know but as I read you, I wonder if I done it that way ;o) I will look through my code tomorrow ;o)

    Clean interfaces are far more important that an extra call. The user won't even notice it.
    Ok, thanks to reassure me ;o) and thanks for your answer.

    Anyway, this is sad but it seems QSystemTrayIcon as the "main widget" or more exactly "main application object" is not the best idea. Modals dialogs can be triggered several time from the QSystemTray as the dialog is not owned by the QSystemTrayIcon which is a QObject and not a QWidget.

    I think there must be good reasons as Qt dev team is really skilled and more skilled than me but I wonder why they didn't make the QSystemTrayIcon a QWidget child as it is a visual item on which users can interact.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSystemTrayIcon as "main window" design issue

    Quote Originally Posted by nooky59 View Post
    Anyway, this is sad but it seems QSystemTrayIcon as the "main widget" or more exactly "main application object" is not the best idea. Modals dialogs can be triggered several time from the QSystemTray as the dialog is not owned by the QSystemTrayIcon which is a QObject and not a QWidget.
    Maybe you could create a hidden widget which will be a parent for your dialogs?

    Quote Originally Posted by nooky59 View Post
    I wonder why they didn't make the QSystemTrayIcon a QWidget child as it is a visual item on which users can interact.
    Maybe because you can only put an icon on the system tray on some systems?

Similar Threads

  1. Dialog and code design issue
    By Gopala Krishna in forum Qt Programming
    Replies: 1
    Last Post: 24th September 2006, 17:54

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.