[PyQt] Inconsistent behavior with multiple inheritance and ConvertToSubClassCode

Nyall Dawson nyall.dawson at gmail.com
Tue Sep 25 08:10:16 BST 2018

Hi list,

I've been struggling for a while with some inconsistent behavior
relating to ConvertToSubClassCode and a multiple inherited class.

The definition currently looks something like:

class LayoutItem : LayoutObject, QGraphicsRectItem
#include "layoutitem.h"
#include "layoutitempicture.h"
#include "layoutitemlabel.h"
    // the conversions have to be static, because they're using
multiple inheritance
    // (seen in PyQt4 .sip files for some QGraphicsItem classes)
    switch ( sipCpp->type() )
      case QGraphicsItem::UserType + 104:
        sipType = sipType_LayoutItemPicture;
        *sipCppRet = static_cast<LayoutItemPicture *>( sipCpp );
      case QGraphicsItem::UserType + 105:
        sipType = sipType_LayoutItemLabel;
        *sipCppRet = static_cast<LayoutItemLabel *>( sipCpp );
        sipType = 0;

While this... sometimes... works correctly, most often LayoutItem
subclasses are not automatically cast to the subclass, and remain as
LayoutItems only. Is the ConvertToSubClassCode incorrect here?


More information about the PyQt mailing list