QSystemTrayIcon in 4.8 - how to delete this thing?
-
As the title says, what is this thing and how do I handle it?
It's a QObject and asks for a QObject as it's parent. But at the same time it has child objects that are QWidgets.
With most QObjects, you can either let the parent delete it when the parent is deleted, or you can delete it yourself. But QSystemTrayIcon doesn't seem to work this way - I've tried making it the child of an arbitrary QObject and then letting it's parent delete it - when I do this, a lingering event gets sent to the QSystemTrayIcon that's been parent-deleted. On OSX this segfaults because it ends up sending an obj message to an invalid object.
This might be because the QMainWindow is going away at the same time in my application.
If I have to delete it explicitly after un-childing it, why? And if that's the case, it sounds like this is timing-dependent or something.
If QSystemTrayIcon really just wants a QWidget as its parent, why isn't its constructor written that way?
-
Hi,
Have a look at the "System Tray Icon Example"
You'l see how to use it
Hope it helps
-
Ok - looks good. So it must be parented to a QWidget, it's constructor signature notwithstanding?
If I wanted to delete one early, before it's parent is deleted, how do I do that? I can't set Qt::WA_DeleteOnClose. Do I just delete it directly? Do I use deleteLater(), in spite of the fact that multiple threads aren't involved?
[quote author="SGaist" date="1399622416"]Hi,
Have a look at the "System Tray Icon Example"
You'l see how to use it
Hope it helps[/quote]
-
No it must not, QWidget is a QObject derived class.
deleteLater is generally the way to go, the event loop will delete it at the best moment.
-
Sorry - I don't understand. Can QSystemTrayIcon be a child of any old QObject (as the ctor signature would suggest), or is it required to be a child of a QWidget (as the example code and my own segfault experience seems to suggest)?
[quote author="SGaist" date="1399668486"]No it must not, QWidget is a QObject derived class.
deleteLater is generally the way to go, the event loop will delete it at the best moment.[/quote]
-
QObject, if you have a crash, then there is something spurious. Can you share the code where you have that crash happening ?