Had a similar issue as OP ( But with Python!! ), Romario's answer got me half way to what i wanted.
In my scenario i have a sys-tray tool where i enforce only one being alive via lockfile. However user feedback requested that if they try launching while already open i provide some sort of feedback.
What i found was on Windows - the Romarios answer will lead icons persisting in the systray - if you call setVisible(False)
before the show()
it will prevent icons appearing/acculumating in the sys-tray :)
My complete sample is
class SimpleNotifier(QtWidgets.QWidget):
def notify_running(self):
tray_icon = QtGui.QIcon(Params.TRAY_ICON)
self.setIcon(tray_icon)
self.setVisible(False)
self.show()
self.showMessage("Hi User", "Application already inside your sys-tray", QtGui.QIcon(Params.TRAY_ICON))
def notify():
app = QtWidgets.QApplication(sys.argv)
notify = HUBController.SimpleNotifier()
notify.notify_running()
app.exit()
notify()
and yes i did sign up for an account after lurking for years just to make this post :
:)