How to pass QSystemTrayIcon control between QDialog and QmainWindow
-
Sure, that would work, but it would cause unneeded flicker in the system tray and generally waste resources. I would just make a single object controlling your QSystemTrayIcon, and create a single instance of that object with the QApplication as its parent. Much easier and cleaner.
-
"tone"? What is that?
I mean to make a single class that is responsible for handling the icon. From where you instantiate that class, is not very relevant. It may be from the main, it may be from the QDialog, or it could even be from a subclassed QApplication. You could even considder making that class a singleton class, so it would instantiated by itself the first time it is accessed. The parent of that class would not be a class that is not around for the whole time you need the icon. That rules out both QDialog and QMainWindow. QApplication would be a logical candidate. In either case, note that the question of who instantiates the object is unrelated to the question of what object will be parent. QDialog can instantiate the object, and still make the qApp the parent.
-
QApplication does not inherit from QWidget. In inherits from QObject (just like QWidget does). Furtunately, QSystemTrayIcon takes a QObject* as the parent argument. So why do you need to try to cast QApplication to a QWidget? That will not work, and is not needed.