[PyQt] Problem/Bug with QSystemTrayIcon and QMenu

Andreas Pakulat apaku at gmx.de
Thu Sep 6 14:12:27 BST 2007


On 06.09.07 13:47:39, Adam Batkin wrote:
> I have reduced my problem down to just a few lines of code, but the basic 
> summary is that when trying to add a QMenu to a QSystemTrayIcon 
> (tray.setContextMenu()), sometimes the menu deletes itself.
[...]
> If I replace the tray.setContextMenu(buildMenu()) line with:
> menu = buildMenu()
> tray.setContextMenu(menu)
> 
> then my output is:
> menu=<PyQt4.QtGui.QMenu object at 0xb7f1c8ac>
> 
> and "died" isn't printed until the menu is actually destroyed (on program 
> exit), which all makes perfect sense since menu is set to an actual object.
> 
> Thoughts?

I think thats normal (Phil will know for sure). I don't know sip
internals, but I think what happens is that the refcount for the
Python-Wrapped QMenu is not incremented in setContextMenu, which is
quite natural as its a C++ function from Qt not knowing anything about
Python. Keeping a reference to the object yourself is the proper
solution here.

Andreas

-- 
Tonight you will pay the wages of sin; Don't forget to leave a tip.


More information about the PyQt mailing list