@@ -270,7 +270,11 @@ PyObject* PythonQtConv::convertQtValueToPythonInternal(int type, const void* dat
270
270
default :
271
271
// check if we have a QList of pointers, which we can circumvent with a QList<void*>
272
272
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
273
276
static int id = QMetaType::type (" QList<void*>" );
277
+ #endif
274
278
PythonQtArgumentFrame_ADD_VARIANT_VALUE_BY_ID (frame, id, ptr);
275
279
// return the constData pointer that will be filled with the result value later on
276
280
ptr = (void *)((QVariant*)ptr)->constData ();
@@ -310,11 +314,17 @@ PyObject* PythonQtConv::convertQtValueToPythonInternal(int type, const void* dat
310
314
void * PythonQtConv::handlePythonToQtAutoConversion (int typeId, PyObject* obj, void * alreadyAllocatedCPPObject, PythonQtArgumentFrame* frame)
311
315
{
312
316
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" );
316
325
static int cursorId = QMetaType::type (" QCursor" );
317
- static int colorId = QMetaType::type (" QColor" );
326
+ static int colorId = QMetaType::type (" QColor" );
327
+ #endif
318
328
static PyObject* qtGlobalColorEnum = PythonQtClassInfo::findEnumWrapper (" Qt::GlobalColor" , nullptr );
319
329
if (typeId == cursorId) {
320
330
static PyObject* qtCursorShapeEnum = PythonQtClassInfo::findEnumWrapper (" Qt::CursorShape" , nullptr );
@@ -728,7 +738,11 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i
728
738
if (info.typeId == PythonQtMethodInfo::Unknown || info.typeId >= QMetaType::User) {
729
739
// check for QList<AnyPtr*> case, where we will use a QList<void*> QVariant
730
740
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
731
744
static int id = QMetaType::type (" QList<void*>" );
745
+ #endif
732
746
if (!alreadyAllocatedCPPObject) {
733
747
PythonQtArgumentFrame_ADD_VARIANT_VALUE_BY_ID_IF_NEEDED (alreadyAllocatedCPPObject, frame, id, ptr);
734
748
ptr = (void *)((QVariant*)ptr)->constData ();
@@ -1094,35 +1108,39 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
1094
1108
) {
1095
1109
// no special type requested
1096
1110
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
1098
1116
} else if (PyBytes_Check (val)) {
1099
1117
#ifdef PY3K
1100
1118
// In Python 3, it is a ByteArray
1101
- type = QVariant::ByteArray ;
1119
+ type = QMetaType::QByteArray ;
1102
1120
#else
1103
1121
// In Python 2, we need to use String, since it might be a string
1104
- type = QVariant::String ;
1122
+ type = QMetaType::QString ;
1105
1123
#endif
1106
1124
} else if (PyUnicode_Check (val)) {
1107
- type = QVariant::String ;
1125
+ type = QMetaType::QString ;
1108
1126
} else if (val == Py_False || val == Py_True) {
1109
- type = QVariant ::Bool;
1127
+ type = QMetaType ::Bool;
1110
1128
#ifndef PY3K
1111
1129
} else if (PyObject_TypeCheck (val, &PyInt_Type)) {
1112
- type = QVariant ::Int;
1130
+ type = QMetaType ::Int;
1113
1131
#endif
1114
1132
} else if (PyLong_Check (val)) {
1115
1133
// return int if the value fits into that range,
1116
1134
// otherwise it would not be possible to get an int from Python 3
1117
1135
qint64 d = PyLong_AsLongLong (val);
1118
1136
if (d > std::numeric_limits<int >::max () ||
1119
1137
d < std::numeric_limits<int >::min ()) {
1120
- type = QVariant ::LongLong;
1138
+ type = QMetaType ::LongLong;
1121
1139
} else {
1122
- type = QVariant ::Int;
1140
+ type = QMetaType ::Int;
1123
1141
}
1124
1142
} else if (PyFloat_Check (val)) {
1125
- type = QVariant ::Double;
1143
+ type = QMetaType ::Double;
1126
1144
} else if (PyObject_TypeCheck (val, &PythonQtInstanceWrapper_Type)) {
1127
1145
PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)val;
1128
1146
// c++ wrapper, check if the class names of the c++ objects match
@@ -1144,11 +1162,15 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
1144
1162
return v;
1145
1163
} else if (val == Py_None) {
1146
1164
// 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
1148
1170
} else if (PyDict_Check (val)) {
1149
- type = QVariant::Map ;
1171
+ type = QMetaType::QVariantMap ;
1150
1172
} else if (PyList_Check (val) || PyTuple_Check (val) || PySequence_Check (val)) {
1151
- type = QVariant::List ;
1173
+ type = QMetaType::QVariantList ;
1152
1174
} else {
1153
1175
// transport the Python objects directly inside of QVariant:
1154
1176
v = PythonQtObjectPtr (val).toVariant ();
@@ -1157,28 +1179,32 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
1157
1179
}
1158
1180
// special type request:
1159
1181
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
1161
1187
return v;
1162
1188
break ;
1163
- case QVariant ::Int:
1189
+ case QMetaType ::Int:
1164
1190
{
1165
1191
int d = PyObjGetInt (val, false , ok);
1166
1192
if (ok) return QVariant (d);
1167
1193
}
1168
1194
break ;
1169
- case QVariant ::UInt:
1195
+ case QMetaType ::UInt:
1170
1196
{
1171
1197
int d = PyObjGetInt (val, false ,ok);
1172
1198
if (ok) v = QVariant ((unsigned int )d);
1173
1199
}
1174
1200
break ;
1175
- case QVariant ::Bool:
1201
+ case QMetaType ::Bool:
1176
1202
{
1177
1203
int d = PyObjGetBool (val,false ,ok);
1178
1204
if (ok) v = QVariant ((bool )(d!=0 ));
1179
1205
}
1180
1206
break ;
1181
- case QVariant ::Double:
1207
+ case QMetaType ::Double:
1182
1208
{
1183
1209
double d = PyObjGetDouble (val,false ,ok);
1184
1210
if (ok) v = QVariant (d);
@@ -1239,7 +1265,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
1239
1265
}
1240
1266
break ;
1241
1267
1242
- case QVariant::ByteArray :
1268
+ case QMetaType::QByteArray :
1243
1269
{
1244
1270
bool ok;
1245
1271
#ifdef PY3K
@@ -1249,20 +1275,20 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
1249
1275
#endif
1250
1276
}
1251
1277
break ;
1252
- case QVariant::String :
1278
+ case QMetaType::QString :
1253
1279
{
1254
1280
bool ok;
1255
1281
v = QVariant (PyObjGetString (val, false , ok));
1256
1282
}
1257
1283
break ;
1258
1284
1259
- case QVariant::Map :
1285
+ case QMetaType::QVariantMap :
1260
1286
pythonToMapVariant<QVariantMap>(val, v);
1261
1287
break ;
1262
- case QVariant::Hash :
1288
+ case QMetaType::QVariantHash :
1263
1289
pythonToMapVariant<QVariantHash>(val, v);
1264
1290
break ;
1265
- case QVariant::List :
1291
+ case QMetaType::QVariantList :
1266
1292
{
1267
1293
bool isListOrTuple = PyList_Check (val) || PyTuple_Check (val);
1268
1294
if (isListOrTuple || PySequence_Check (val)) {
@@ -1288,7 +1314,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
1288
1314
}
1289
1315
}
1290
1316
break ;
1291
- case QVariant::StringList :
1317
+ case QMetaType::QStringList :
1292
1318
{
1293
1319
bool ok;
1294
1320
QStringList l = PyObjToStringList (val, false , ok);
@@ -1308,7 +1334,11 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
1308
1334
// Try to convert the object to a QVariant based on the typeName
1309
1335
bool ok;
1310
1336
bool isPtr = false ;
1337
+ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1338
+ QByteArray typeName = QMetaType (type).name ();
1339
+ #else
1311
1340
QByteArray typeName = QMetaType::typeName (type);
1341
+ #endif
1312
1342
if (typeName.endsWith (" *" )) {
1313
1343
isPtr = true ;
1314
1344
typeName.truncate (typeName.length () - 1 );
@@ -1323,7 +1353,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
1323
1353
}
1324
1354
}
1325
1355
}
1326
- } else if (static_cast <std::uint32_t >(type) >= QVariant::UserType ) {
1356
+ } else if (static_cast <std::uint32_t >(type) >= QMetaType::User ) {
1327
1357
// not an instance wrapper, but there might be other converters
1328
1358
// Maybe we have a special converter that is registered for that type:
1329
1359
PythonQtConvertPythonToMetaTypeCB* converter = _pythonToMetaTypeConverters.value (type);
@@ -1504,66 +1534,66 @@ bool PythonQtConv::ConvertPythonListToQListOfPointerType(PyObject* obj, QList<vo
1504
1534
QString PythonQtConv::CPPObjectToString (int type, const void * data) {
1505
1535
QString r;
1506
1536
switch (type) {
1507
- case QVariant::Size : {
1537
+ case QMetaType::QSize : {
1508
1538
const QSize* s = static_cast <const QSize*>(data);
1509
1539
r = QString::number (s->width ()) + " , " + QString::number (s->height ());
1510
1540
}
1511
1541
break ;
1512
- case QVariant::SizeF : {
1542
+ case QMetaType::QSizeF : {
1513
1543
const QSizeF* s = static_cast <const QSizeF*>(data);
1514
1544
r = QString::number (s->width ()) + " , " + QString::number (s->height ());
1515
1545
}
1516
1546
break ;
1517
- case QVariant::Point : {
1547
+ case QMetaType::QPoint : {
1518
1548
const QPoint* s = static_cast <const QPoint*>(data);
1519
1549
r = QString::number (s->x ()) + " , " + QString::number (s->y ());
1520
1550
}
1521
1551
break ;
1522
- case QVariant::PointF : {
1552
+ case QMetaType::QPointF : {
1523
1553
const QPointF* s = static_cast <const QPointF*>(data);
1524
1554
r = QString::number (s->x ()) + " , " + QString::number (s->y ());
1525
1555
}
1526
1556
break ;
1527
- case QVariant::Rect : {
1557
+ case QMetaType::QRect : {
1528
1558
const QRect* s = static_cast <const QRect*>(data);
1529
1559
r = QString::number (s->x ()) + " , " + QString::number (s->y ());
1530
1560
r += " , " + QString::number (s->width ()) + " , " + QString::number (s->height ());
1531
1561
}
1532
1562
break ;
1533
- case QVariant::RectF : {
1563
+ case QMetaType::QRectF : {
1534
1564
const QRectF* s = static_cast <const QRectF*>(data);
1535
1565
r = QString::number (s->x ()) + " , " + QString::number (s->y ());
1536
1566
r += " , " + QString::number (s->width ()) + " , " + QString::number (s->height ());
1537
1567
}
1538
1568
break ;
1539
- case QVariant::Date : {
1569
+ case QMetaType::QDate : {
1540
1570
const QDate* s = static_cast <const QDate*>(data);
1541
1571
r = s->toString (Qt::ISODate);
1542
1572
}
1543
1573
break ;
1544
- case QVariant::DateTime : {
1574
+ case QMetaType::QDateTime : {
1545
1575
const QDateTime* s = static_cast <const QDateTime*>(data);
1546
1576
r = s->toString (Qt::ISODate);
1547
1577
}
1548
1578
break ;
1549
- case QVariant::Time : {
1579
+ case QMetaType::QTime : {
1550
1580
const QTime* s = static_cast <const QTime*>(data);
1551
1581
r = s->toString (Qt::ISODate);
1552
1582
}
1553
1583
break ;
1554
- case QVariant::Pixmap :
1584
+ case QMetaType::QPixmap :
1555
1585
{
1556
1586
const QPixmap* s = static_cast <const QPixmap*>(data);
1557
1587
r = QString (" Pixmap " ) + QString::number (s->width ()) + " , " + QString::number (s->height ());
1558
1588
}
1559
1589
break ;
1560
- case QVariant::Image :
1590
+ case QMetaType::QImage :
1561
1591
{
1562
1592
const QImage* s = static_cast <const QImage*>(data);
1563
1593
r = QString (" Image " ) + QString::number (s->width ()) + " , " + QString::number (s->height ());
1564
1594
}
1565
1595
break ;
1566
- case QVariant::Url :
1596
+ case QMetaType::QUrl :
1567
1597
{
1568
1598
const QUrl* s = static_cast <const QUrl*>(data);
1569
1599
r = s->toString ();
@@ -1573,7 +1603,7 @@ QString PythonQtConv::CPPObjectToString(int type, const void* data) {
1573
1603
default :
1574
1604
// this creates a copy, but that should not be expensive for typical simple variants
1575
1605
// (but we do not want to do this for our own user types!)
1576
- if (type>0 && type < (int )QVariant::UserType ) {
1606
+ if (type>0 && type < (int )QMetaType::User ) {
1577
1607
r = variantFromType (type, data).toString ();
1578
1608
}
1579
1609
}
@@ -1583,13 +1613,19 @@ QString PythonQtConv::CPPObjectToString(int type, const void* data) {
1583
1613
PyObject* PythonQtConv::createCopyFromMetaType ( int type, const void * data )
1584
1614
{
1585
1615
// if the type is known, we can construct it via QMetaType::construct
1586
- #if ( QT_VERSION >= QT_VERSION_CHECK(5,0,0) )
1587
- void * newCPPObject = QMetaType::create (type, data);
1616
+ #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1617
+ void * newCPPObject = QMetaType (type).create (data);
1618
+ // XXX this could be optimized by using metatypeid directly
1619
+ PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)PythonQt::priv ()->wrapPtr (newCPPObject, QMetaType (type).name ());
1620
+ #elif QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
1621
+ void * newCPPObject = QMetaType::create (type, data);
1622
+ // XXX this could be optimized by using metatypeid directly
1623
+ PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)PythonQt::priv ()->wrapPtr (newCPPObject, QMetaType::typeName (type));
1588
1624
#else
1589
- void * newCPPObject = QMetaType::construct (type, data);
1590
- #endif
1625
+ void * newCPPObject = QMetaType::construct (type, data);
1591
1626
// XXX this could be optimized by using metatypeid directly
1592
1627
PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)PythonQt::priv ()->wrapPtr (newCPPObject, QMetaType::typeName (type));
1628
+ #endif
1593
1629
wrap->_ownedByPythonQt = true ;
1594
1630
wrap->_useQMetaTypeDestroy = true ;
1595
1631
return (PyObject*)wrap;
0 commit comments