[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
{
%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?
Nyall
More information about the PyQt
mailing list