@@ -270,7 +270,11 @@ PyObject* PythonQtConv::convertQtValueToPythonInternal(int type, const void* dat
270270 default :
271271 // check if we have a QList of pointers, which we can circumvent with a QList<void*>
272272 if (info.isQList && (info.innerNamePointerCount == 1 )) {
273+ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
274+ static int id = QMetaType::fromName (" QList<void*>" ).id ();
275+ #else
273276 static int id = QMetaType::type (" QList<void*>" );
277+ #endif
274278 PythonQtArgumentFrame_ADD_VARIANT_VALUE_BY_ID (frame, id, ptr);
275279 // return the constData pointer that will be filled with the result value later on
276280 ptr = (void *)((QVariant*)ptr)->constData ();
@@ -310,11 +314,17 @@ PyObject* PythonQtConv::convertQtValueToPythonInternal(int type, const void* dat
310314void * PythonQtConv::handlePythonToQtAutoConversion (int typeId, PyObject* obj, void * alreadyAllocatedCPPObject, PythonQtArgumentFrame* frame)
311315{
312316 void * ptr = alreadyAllocatedCPPObject;
313-
314- static int penId = QMetaType::type (" QPen" );
315- static int brushId = QMetaType::type (" QBrush" );
317+ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
318+ static int penId = QMetaType::fromName (" QPen" ).id ();
319+ static int brushId = QMetaType::fromName (" QBrush" ).id ();
320+ static int cursorId = QMetaType::fromName (" QCursor" ).id ();
321+ static int colorId = QMetaType::fromName (" QColor" ).id ();
322+ #else
323+ static int penId = QMetaType::type (" QPen" );
324+ static int brushId = QMetaType::type (" QBrush" );
316325 static int cursorId = QMetaType::type (" QCursor" );
317- static int colorId = QMetaType::type (" QColor" );
326+ static int colorId = QMetaType::type (" QColor" );
327+ #endif
318328 static PyObject* qtGlobalColorEnum = PythonQtClassInfo::findEnumWrapper (" Qt::GlobalColor" , nullptr );
319329 if (typeId == cursorId) {
320330 static PyObject* qtCursorShapeEnum = PythonQtClassInfo::findEnumWrapper (" Qt::CursorShape" , nullptr );
@@ -728,7 +738,11 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i
728738 if (info.typeId == PythonQtMethodInfo::Unknown || info.typeId >= QMetaType::User) {
729739 // check for QList<AnyPtr*> case, where we will use a QList<void*> QVariant
730740 if (info.isQList && (info.innerNamePointerCount == 1 )) {
741+ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
742+ static int id = QMetaType::fromName (" QList<void*>" ).id ();
743+ #else
731744 static int id = QMetaType::type (" QList<void*>" );
745+ #endif
732746 if (!alreadyAllocatedCPPObject) {
733747 PythonQtArgumentFrame_ADD_VARIANT_VALUE_BY_ID_IF_NEEDED (alreadyAllocatedCPPObject, frame, id, ptr);
734748 ptr = (void *)((QVariant*)ptr)->constData ();
@@ -1094,35 +1108,39 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
10941108 ) {
10951109 // no special type requested
10961110 if (val == nullptr ) {
1097- type = QVariant::Invalid;
1111+ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1112+ type = QMetaType::UnknownType;
1113+ #else
1114+ type = 0 ; // Equivalent to QVariant::Invalid or unregistered type
1115+ #endif
10981116 } else if (PyBytes_Check (val)) {
10991117#ifdef PY3K
11001118 // In Python 3, it is a ByteArray
1101- type = QVariant::ByteArray ;
1119+ type = QMetaType::QByteArray ;
11021120#else
11031121 // In Python 2, we need to use String, since it might be a string
1104- type = QVariant::String ;
1122+ type = QMetaType::QString ;
11051123#endif
11061124 } else if (PyUnicode_Check (val)) {
1107- type = QVariant::String ;
1125+ type = QMetaType::QString ;
11081126 } else if (val == Py_False || val == Py_True) {
1109- type = QVariant ::Bool;
1127+ type = QMetaType ::Bool;
11101128#ifndef PY3K
11111129 } else if (PyObject_TypeCheck (val, &PyInt_Type)) {
1112- type = QVariant ::Int;
1130+ type = QMetaType ::Int;
11131131#endif
11141132 } else if (PyLong_Check (val)) {
11151133 // return int if the value fits into that range,
11161134 // otherwise it would not be possible to get an int from Python 3
11171135 qint64 d = PyLong_AsLongLong (val);
11181136 if (d > std::numeric_limits<int >::max () ||
11191137 d < std::numeric_limits<int >::min ()) {
1120- type = QVariant ::LongLong;
1138+ type = QMetaType ::LongLong;
11211139 } else {
1122- type = QVariant ::Int;
1140+ type = QMetaType ::Int;
11231141 }
11241142 } else if (PyFloat_Check (val)) {
1125- type = QVariant ::Double;
1143+ type = QMetaType ::Double;
11261144 } else if (PyObject_TypeCheck (val, &PythonQtInstanceWrapper_Type)) {
11271145 PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)val;
11281146 // c++ wrapper, check if the class names of the c++ objects match
@@ -1144,11 +1162,15 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
11441162 return v;
11451163 } else if (val == Py_None) {
11461164 // none is invalid
1147- type = QVariant::Invalid;
1165+ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1166+ type = QMetaType::UnknownType;
1167+ #else
1168+ type = 0 ; // Equivalent to QVariant::Invalid or unregistered type
1169+ #endif
11481170 } else if (PyDict_Check (val)) {
1149- type = QVariant::Map ;
1171+ type = QMetaType::QVariantMap ;
11501172 } else if (PyList_Check (val) || PyTuple_Check (val) || PySequence_Check (val)) {
1151- type = QVariant::List ;
1173+ type = QMetaType::QVariantList ;
11521174 } else {
11531175 // transport the Python objects directly inside of QVariant:
11541176 v = PythonQtObjectPtr (val).toVariant ();
@@ -1157,28 +1179,32 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
11571179 }
11581180 // special type request:
11591181 switch (type) {
1160- case QVariant::Invalid:
1182+ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1183+ case QMetaType::UnknownType:
1184+ #else
1185+ case 0 : // Equivalent to QVariant::Invalid or unregistered type
1186+ #endif
11611187 return v;
11621188 break ;
1163- case QVariant ::Int:
1189+ case QMetaType ::Int:
11641190 {
11651191 int d = PyObjGetInt (val, false , ok);
11661192 if (ok) return QVariant (d);
11671193 }
11681194 break ;
1169- case QVariant ::UInt:
1195+ case QMetaType ::UInt:
11701196 {
11711197 int d = PyObjGetInt (val, false ,ok);
11721198 if (ok) v = QVariant ((unsigned int )d);
11731199 }
11741200 break ;
1175- case QVariant ::Bool:
1201+ case QMetaType ::Bool:
11761202 {
11771203 int d = PyObjGetBool (val,false ,ok);
11781204 if (ok) v = QVariant ((bool )(d!=0 ));
11791205 }
11801206 break ;
1181- case QVariant ::Double:
1207+ case QMetaType ::Double:
11821208 {
11831209 double d = PyObjGetDouble (val,false ,ok);
11841210 if (ok) v = QVariant (d);
@@ -1239,7 +1265,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
12391265 }
12401266 break ;
12411267
1242- case QVariant::ByteArray :
1268+ case QMetaType::QByteArray :
12431269 {
12441270 bool ok;
12451271#ifdef PY3K
@@ -1249,20 +1275,20 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
12491275#endif
12501276 }
12511277 break ;
1252- case QVariant::String :
1278+ case QMetaType::QString :
12531279 {
12541280 bool ok;
12551281 v = QVariant (PyObjGetString (val, false , ok));
12561282 }
12571283 break ;
12581284
1259- case QVariant::Map :
1285+ case QMetaType::QVariantMap :
12601286 pythonToMapVariant<QVariantMap>(val, v);
12611287 break ;
1262- case QVariant::Hash :
1288+ case QMetaType::QVariantHash :
12631289 pythonToMapVariant<QVariantHash>(val, v);
12641290 break ;
1265- case QVariant::List :
1291+ case QMetaType::QVariantList :
12661292 {
12671293 bool isListOrTuple = PyList_Check (val) || PyTuple_Check (val);
12681294 if (isListOrTuple || PySequence_Check (val)) {
@@ -1288,7 +1314,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
12881314 }
12891315 }
12901316 break ;
1291- case QVariant::StringList :
1317+ case QMetaType::QStringList :
12921318 {
12931319 bool ok;
12941320 QStringList l = PyObjToStringList (val, false , ok);
@@ -1308,7 +1334,11 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
13081334 // Try to convert the object to a QVariant based on the typeName
13091335 bool ok;
13101336 bool isPtr = false ;
1337+ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1338+ QByteArray typeName = QMetaType (type).name ();
1339+ #else
13111340 QByteArray typeName = QMetaType::typeName (type);
1341+ #endif
13121342 if (typeName.endsWith (" *" )) {
13131343 isPtr = true ;
13141344 typeName.truncate (typeName.length () - 1 );
@@ -1323,7 +1353,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
13231353 }
13241354 }
13251355 }
1326- } else if (static_cast <std::uint32_t >(type) >= QVariant::UserType ) {
1356+ } else if (static_cast <std::uint32_t >(type) >= QMetaType::User ) {
13271357 // not an instance wrapper, but there might be other converters
13281358 // Maybe we have a special converter that is registered for that type:
13291359 PythonQtConvertPythonToMetaTypeCB* converter = _pythonToMetaTypeConverters.value (type);
@@ -1505,66 +1535,66 @@ bool PythonQtConv::ConvertPythonListToQListOfPointerType(PyObject* obj, QList<vo
15051535QString PythonQtConv::CPPObjectToString (int type, const void * data) {
15061536 QString r;
15071537 switch (type) {
1508- case QVariant::Size : {
1538+ case QMetaType::QSize : {
15091539 const QSize* s = static_cast <const QSize*>(data);
15101540 r = QString::number (s->width ()) + " , " + QString::number (s->height ());
15111541 }
15121542 break ;
1513- case QVariant::SizeF : {
1543+ case QMetaType::QSizeF : {
15141544 const QSizeF* s = static_cast <const QSizeF*>(data);
15151545 r = QString::number (s->width ()) + " , " + QString::number (s->height ());
15161546 }
15171547 break ;
1518- case QVariant::Point : {
1548+ case QMetaType::QPoint : {
15191549 const QPoint* s = static_cast <const QPoint*>(data);
15201550 r = QString::number (s->x ()) + " , " + QString::number (s->y ());
15211551 }
15221552 break ;
1523- case QVariant::PointF : {
1553+ case QMetaType::QPointF : {
15241554 const QPointF* s = static_cast <const QPointF*>(data);
15251555 r = QString::number (s->x ()) + " , " + QString::number (s->y ());
15261556 }
15271557 break ;
1528- case QVariant::Rect : {
1558+ case QMetaType::QRect : {
15291559 const QRect* s = static_cast <const QRect*>(data);
15301560 r = QString::number (s->x ()) + " , " + QString::number (s->y ());
15311561 r += " , " + QString::number (s->width ()) + " , " + QString::number (s->height ());
15321562 }
15331563 break ;
1534- case QVariant::RectF : {
1564+ case QMetaType::QRectF : {
15351565 const QRectF* s = static_cast <const QRectF*>(data);
15361566 r = QString::number (s->x ()) + " , " + QString::number (s->y ());
15371567 r += " , " + QString::number (s->width ()) + " , " + QString::number (s->height ());
15381568 }
15391569 break ;
1540- case QVariant::Date : {
1570+ case QMetaType::QDate : {
15411571 const QDate* s = static_cast <const QDate*>(data);
15421572 r = s->toString (Qt::ISODate);
15431573 }
15441574 break ;
1545- case QVariant::DateTime : {
1575+ case QMetaType::QDateTime : {
15461576 const QDateTime* s = static_cast <const QDateTime*>(data);
15471577 r = s->toString (Qt::ISODate);
15481578 }
15491579 break ;
1550- case QVariant::Time : {
1580+ case QMetaType::QTime : {
15511581 const QTime* s = static_cast <const QTime*>(data);
15521582 r = s->toString (Qt::ISODate);
15531583 }
15541584 break ;
1555- case QVariant::Pixmap :
1585+ case QMetaType::QPixmap :
15561586 {
15571587 const QPixmap* s = static_cast <const QPixmap*>(data);
15581588 r = QString (" Pixmap " ) + QString::number (s->width ()) + " , " + QString::number (s->height ());
15591589 }
15601590 break ;
1561- case QVariant::Image :
1591+ case QMetaType::QImage :
15621592 {
15631593 const QImage* s = static_cast <const QImage*>(data);
15641594 r = QString (" Image " ) + QString::number (s->width ()) + " , " + QString::number (s->height ());
15651595 }
15661596 break ;
1567- case QVariant::Url :
1597+ case QMetaType::QUrl :
15681598 {
15691599 const QUrl* s = static_cast <const QUrl*>(data);
15701600 r = s->toString ();
@@ -1574,7 +1604,7 @@ QString PythonQtConv::CPPObjectToString(int type, const void* data) {
15741604 default :
15751605 // this creates a copy, but that should not be expensive for typical simple variants
15761606 // (but we do not want to do this for our own user types!)
1577- if (type>0 && type < (int )QVariant::UserType ) {
1607+ if (type>0 && type < (int )QMetaType::User ) {
15781608 r = variantFromType (type, data).toString ();
15791609 }
15801610 }
@@ -1584,13 +1614,19 @@ QString PythonQtConv::CPPObjectToString(int type, const void* data) {
15841614PyObject* PythonQtConv::createCopyFromMetaType ( int type, const void * data )
15851615{
15861616 // if the type is known, we can construct it via QMetaType::construct
1587- #if ( QT_VERSION >= QT_VERSION_CHECK(5,0,0) )
1588- void * newCPPObject = QMetaType::create (type, data);
1617+ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1618+ void * newCPPObject = QMetaType (type).create (data);
1619+ // XXX this could be optimized by using metatypeid directly
1620+ PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)PythonQt::priv ()->wrapPtr (newCPPObject, QMetaType (type).name ());
1621+ #elif QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
1622+ void * newCPPObject = QMetaType::create (type, data);
1623+ // XXX this could be optimized by using metatypeid directly
1624+ PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)PythonQt::priv ()->wrapPtr (newCPPObject, QMetaType::typeName (type));
15891625#else
1590- void * newCPPObject = QMetaType::construct (type, data);
1591- #endif
1626+ void * newCPPObject = QMetaType::construct (type, data);
15921627 // XXX this could be optimized by using metatypeid directly
15931628 PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)PythonQt::priv ()->wrapPtr (newCPPObject, QMetaType::typeName (type));
1629+ #endif
15941630 wrap->_ownedByPythonQt = true ;
15951631 wrap->_useQMetaTypeDestroy = true ;
15961632 return (PyObject*)wrap;
0 commit comments