[PyQt] QSystemTrayIcon not hide when quit program

Erik Hvatum ice.rikh at gmail.com
Thu Apr 30 17:59:53 BST 2015


On Sun, Apr 26, 2015 at 8:29 AM, Flya Flyaa <flyaflyaa at gmail.com> wrote:

> I found when exit the program, the system tray icon is still here.
>
> I tried example code in folder PyQt-gpl-5.4.1\examples\desktop\systray, it
> also has this problem.
>
> My system is windows xp 32 bit, python 2.7 with code PyQt-gpl-5.4.1.
>

It is generally not safe to assume that objects are destroyed at exit.  The
underlying memory is often simply released.  The problem here is that a
systray icon will remain visible until something like
shell_notifyicon(NMI_DELETE, handle) is called, and that call happens in
QSystemTrayIcon's destructor.  (I haven't done any winapi development for
about seven years; that call may not be exactly correct).

Python provides various mechanisms for ensuring destruction such as the
*with* statement, but in this case, I would simply call
systemtrayiconinstance.hide() the instant that the event triggering a
graceful exit occurs.

Cheers,
Erik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150430/f302881b/attachment.html>


More information about the PyQt mailing list