[PyQt] PyQt 4.10.2 Bug

Casey Vanover cvanover at rhythm.com
Thu Aug 15 19:54:57 BST 2013


I recently tried to upgrade to the newest version of PyQt4 and 
encountered an "interesting" bug. The use case is this: I have a 
QMenuBar created in C++. I'm creating a QtGui.QMenu in python and adding 
subclasses (called _MenuItem) of QtGui.QAction to them. It looks 
something like this:

<pseudocode>
# get the menu bar (originally created in C++ code)
menuBar = getMainWindow().menuWidget().findChild(QtGui.QMenuBar)

# add our python menu
menu = QtGui.QMenu("foo", menuBar)

# add our subclass of QtGui.QAction. the action is parented to 'menu'
action = _MenuItem("test", menu)
menu.addAction(action)
</pseudocode>

At this point, if I print "menu.actions()", I'll get something like this:

[<_MenuAction object at 0x5090628>]

However, if I don't keep my own reference to 'menu' or 'action' 
(relying, instead, on Qt's own reference counting system), when I leave 
the function I'll get this:

menu = getMenu("test")
print menu.actions()

# [<PyQt4.QtGui.QAction object at 0x5090628>]


So, it appears it lost the typeinfo of the subclass. More importantly 
(for me, at least), the action no longer behaves like an instance of the 
subclass. The triggered signal no longer calls the custom function in 
the class it was connected to. For the record, this worked in my 
previous version which was:

sip = 4.10.2
PyQt = 4.7.3








More information about the PyQt mailing list