[PyQt] Latest PyQt fails compile OSX10.7.5 Qt5.3b conversion from 'long' to 'QFlag' is ambiguous

bootch at nc.rr.com bootch at nc.rr.com
Tue Apr 15 13:17:36 BST 2014


Reading qtbase/src/corelib/global/qflags.h seems to indicate that a QFlag is an 
int (32 bit) even on 64-bit platforms. 
There is an assertion there: 
 
 Q_STATIC_ASSERT_X((sizeof(Enum) <= sizeof(int)), 
"QFlags uses an int as storage, so an enum with underlying " 
"long long will overflow."); 
 
And there is no definition for QFlag(long) on a 64-bit platform (which Darwin 
is) : 
 
class QFlag 
{ 
int i; 
public: 
#if !defined(__LP64__) && !defined(Q_QDOC) 
Q_DECL_CONSTEXPR inline QFlag(long ai) : i(int(ai)) {} 
Q_DECL_CONSTEXPR inline QFlag(ulong ai) : i(int(long(ai))) {} 
#endif 
Q_DECL_CONSTEXPR inline QFlag(int ai) : i(ai) {} 
Q_DECL_CONSTEXPR inline QFlag(uint ai) : i(int(ai)) {} 
Q_DECL_CONSTEXPR inline QFlag(short ai) : i(int(ai)) {} 
Q_DECL_CONSTEXPR inline QFlag(ushort ai) : i(int(uint(ai))) {} 
Q_DECL_CONSTEXPR inline operator int() const { return i; } 
Q_DECL_CONSTEXPR inline operator uint() const { return uint(i); } 
}; 
Q_DECLARE_TYPEINFO(QFlag, Q_PRIMITIVE_TYPE); 
 
 
So I don't understand this fragment from PyQtxx/sip/QtCore: 
 
%ConvertToTypeCode 
// Allow an instance of the base enum whenever a QFlags is expected. 
 
if (sipIsErr == NULL) 
    return (PyObject_TypeCheck(sipPy, sipTypeAsPyTypeObject(sipType_ENUM)) || 
            sipCanConvertToType(sipPy, sipType_QFlags, SIP_NO_CONVERTORS)); 
 
if (PyObject_TypeCheck(sipPy, sipTypeAsPyTypeObject(sipType_ENUM))) 
{ 
    *sipCppPtr = new QFlags(SIPLong_AsLong(sipPy)); 
 
 
Which seems to be converting to long. 
 
My understanding of this code is limited, but it seems to me that the PyQt code 
converting to long is an ancient relic from years ago when an int could be 
16-bits and a long was 32-bits. 


More information about the PyQt mailing list