PDA

View Full Version : QSystemTrayIcon as "main window" design issue



nooky59
9th July 2008, 17:36
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 ?

jacek
9th July 2008, 21:40
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.

nooky59
10th July 2008, 10:50
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)

jacek
11th July 2008, 00:37
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.


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.

nooky59
14th July 2008, 23:25
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.

jacek
17th July 2008, 13:15
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?


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?