[PyQt] Inconsistent behavior with multiple inheritance and ConvertToSubClassCode
Phil Thompson
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
> {
> %TypeHeaderCode
> #include "layoutitem.h"
> #include "layoutitempicture.h"
> #include "layoutitemlabel.h"
> %End
> %ConvertToSubClassCode
> // 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 );
> break;
> case QGraphicsItem::UserType + 105:
> sipType = sipType_LayoutItemLabel;
> *sipCppRet = static_cast<LayoutItemLabel *>( sipCpp );
> break;
> default:
> sipType = 0;
> }
> %End
> public:
> ...
>
>
> 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.
Phil
More information about the PyQt
mailing list