[PyQt] Inconsistent behavior with multiple inheritance and ConvertToSubClassCode
phil at riverbankcomputing.com
Sun Sep 30 13:46:21 BST 2018
On 25 Sep 2018, at 8:10 am, Nyall Dawson <nyall.dawson at gmail.com> wrote:
> 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?
There is nothing obviously wrong. You probably need to put in debug statements to work out exactly what is happening.
More information about the PyQt