[PyQt] PyQt snapshot crash on Qt5.4 with bogus QGraphicsVideoItem instance

Phil Thompson phil at riverbankcomputing.com
Fri Jan 2 16:10:07 GMT 2015


On 02/01/2015 3:31 pm, Phil Thompson wrote:
> On 02/01/2015 2:28 pm, lloyd konneker wrote:
>> This is just a follow up to more clearly document the problem and
>> solution (since I garbled the thread.)
>> 
>> If you are using QGraphicsItems and PyQt and you experience symptoms
>> where an object is mysteriously of type QGraphicsVideoItem (and you
>> are NOT using QGraphicsVideoItem):
>> 
>> The solution is in the file
>> PyQt…/sip/QMultimediaWidgets/qgraphicsvideoitem.sip, delete the code
>> between “%ConvertToSubClassCode” and “%End”, and then totally rebuild
>> PyQt (starting with the configure step.)   It is not enough to just re
>> make, since the configure step is when code is generated using the
>> .sip files.
>> 
>> My understanding of the situation:  QGraphicsItems are lightweight
>> objects not inheriting QObject and thus having no introspection.  For
>> certain calls to Qt that return QGraphicsItem objects (or containers
>> of same) PyQt wraps  the returned objects but must determine their
>> type (subclass of QGraphicsItem) by calling their type() method.
>> However, QGraphicsVideoItem fails to implement the type() method
>> (which probably should be reported as a bug in Qt).  So PyQt ‘casts’
>> the objects to QGraphicsVideoItem (unless you follow the solution.)
> 
> Thanks for confirming that the hack worked.
> 
> It's only a problem if you create a QGraphicsItem yourself and also
> don't reimplement the type() method for it.
> 
> I'll improve the test in tonight's snapshot.

Actually I don't think I can improve it (given the Qt bug). If I remove 
the test completely then that might break existing programs.

...so I think you just need to make sure you implement type().

Phil


More information about the PyQt mailing list