PythonQt
Classes | Macros | Typedefs | Functions
PythonQtConversion.h File Reference
#include "PythonQtPythonInclude.h"
#include "PythonQt.h"
#include "PythonQtMisc.h"
#include "PythonQtClassInfo.h"
#include "PythonQtMethodInfo.h"
#include <QList>
#include <vector>

Go to the source code of this file.

Classes

class  PythonQtConv
 a static class that offers methods for type conversion More...
 

Macros

#define PythonQtRegisterListTemplateConverter(type, innertype)
 
#define PythonQtRegisterListTemplateConverterForKnownClass(type, innertype)
 
#define PythonQtRegisterQPairConverter(type1, type2)
 
#define PythonQtRegisterIntegerMapConverter(type, innertype)
 
#define PythonQtRegisterListTemplateQPairConverter(listtype, type1, type2)
 
#define PythonQtRegisterToolClassesTemplateConverter(innertype)
 
#define PythonQtRegisterToolClassesTemplateConverterForKnownClass(innertype)
 

Typedefs

typedef PyObjectPythonQtConvertMetaTypeToPythonCB(const void *inObject, int metaTypeId)
 
typedef bool PythonQtConvertPythonToMetaTypeCB(PyObject *inObject, void *outObject, int metaTypeId, bool strict)
 
typedef QVariant PythonQtConvertPythonSequenceToQVariantListCB(PyObject *inObject)
 

Functions

template<class ListType , class T >
PyObjectPythonQtConvertListOfValueTypeToPythonList (const void *inList, int metaTypeId)
 
template<class ListType , class T >
bool PythonQtConvertPythonListToListOfValueType (PyObject *obj, void *outList, int metaTypeId, bool)
 
template<class ListType , class T >
PyObjectPythonQtConvertListOfKnownClassToPythonList (const void *inList, int metaTypeId)
 
template<class ListType , class T >
bool PythonQtConvertPythonListToListOfKnownClass (PyObject *obj, void *outList, int metaTypeId, bool)
 
template<class T1 , class T2 >
PyObjectPythonQtConvertPairToPython (const void *inPair, int metaTypeId)
 
template<class T1 , class T2 >
bool PythonQtConvertPythonToPair (PyObject *obj, void *outPair, int metaTypeId, bool)
 
template<class ListType , class T1 , class T2 >
PyObjectPythonQtConvertListOfPairToPythonList (const void *inList, int metaTypeId)
 
template<class ListType , class T1 , class T2 >
bool PythonQtConvertPythonListToListOfPair (PyObject *obj, void *outList, int metaTypeId, bool)
 
template<class MapType , class T >
PyObjectPythonQtConvertIntegerMapToPython (const void *inMap, int metaTypeId)
 
template<class MapType , class T >
bool PythonQtConvertPythonToIntegerMap (PyObject *val, void *outMap, int metaTypeId, bool)
 

Detailed Description

Author
Florian Link
Last changed by
Author
florian
Date
2006-05

Definition in file PythonQtConversion.h.

Macro Definition Documentation

◆ PythonQtRegisterIntegerMapConverter

#define PythonQtRegisterIntegerMapConverter (   type,
  innertype 
)
Value:
{ \
int typeId = qRegisterMetaType<type<int, innertype>>(#type "<int, " #innertype ">"); \
PythonQtConv::registerPythonToMetaTypeConverter(typeId, \
PythonQtConv::registerMetaTypeToPythonConverter(typeId, \
}
PyObject * PythonQtConvertPairToPython(const void *inPair, int metaTypeId)
PyObject * PythonQtConvertIntegerMapToPython(const void *inMap, int metaTypeId)
bool PythonQtConvertPythonToIntegerMap(PyObject *val, void *outMap, int metaTypeId, bool)

Definition at line 83 of file PythonQtConversion.h.

84 { \
85 int typeId = qRegisterMetaType<type<int, innertype>>(#type "<int, " #innertype ">"); \
86 PythonQtConv::registerPythonToMetaTypeConverter(typeId, \
88 PythonQtConv::registerMetaTypeToPythonConverter(typeId, \
90 }

◆ PythonQtRegisterListTemplateConverter

#define PythonQtRegisterListTemplateConverter (   type,
  innertype 
)
Value:
{ \
int typeId = qRegisterMetaType<type<innertype>>(#type "<" #innertype ">"); \
PythonQtConv::registerPythonToMetaTypeConverter(typeId, \
PythonQtConv::registerMetaTypeToPythonConverter(typeId, \
}
PyObject * PythonQtConvertListOfValueTypeToPythonList(const void *inList, int metaTypeId)
bool PythonQtConvertPythonListToListOfValueType(PyObject *obj, void *outList, int metaTypeId, bool)

Definition at line 58 of file PythonQtConversion.h.

59 { \
60 int typeId = qRegisterMetaType<type<innertype>>(#type "<" #innertype ">"); \
61 PythonQtConv::registerPythonToMetaTypeConverter(typeId, \
63 PythonQtConv::registerMetaTypeToPythonConverter(typeId, \
65 }

◆ PythonQtRegisterListTemplateConverterForKnownClass

#define PythonQtRegisterListTemplateConverterForKnownClass (   type,
  innertype 
)
Value:
{ \
int typeId = qRegisterMetaType<type<innertype>>(#type "<" #innertype ">"); \
PythonQtConv::registerPythonToMetaTypeConverter(typeId, \
PythonQtConv::registerMetaTypeToPythonConverter(typeId, \
}
bool PythonQtConvertPythonListToListOfKnownClass(PyObject *obj, void *outList, int metaTypeId, bool)
PyObject * PythonQtConvertListOfKnownClassToPythonList(const void *inList, int metaTypeId)

Definition at line 67 of file PythonQtConversion.h.

68 { \
69 int typeId = qRegisterMetaType<type<innertype>>(#type "<" #innertype ">"); \
70 PythonQtConv::registerPythonToMetaTypeConverter(typeId, \
72 PythonQtConv::registerMetaTypeToPythonConverter(typeId, \
74 }

◆ PythonQtRegisterListTemplateQPairConverter

#define PythonQtRegisterListTemplateQPairConverter (   listtype,
  type1,
  type2 
)
Value:
{ \
int typeId = qRegisterMetaType<listtype<QPair<type1, type2>>>(#listtype "<QPair<" #type1 "," #type2 ">>"); \
PythonQtConv::registerPythonToMetaTypeConverter(typeId, \
PythonQtConv::registerMetaTypeToPythonConverter(typeId, \
}
bool PythonQtConvertPythonListToListOfPair(PyObject *obj, void *outList, int metaTypeId, bool)
PyObject * PythonQtConvertListOfPairToPythonList(const void *inList, int metaTypeId)

Definition at line 92 of file PythonQtConversion.h.

93 { \
95 int typeId = qRegisterMetaType<listtype<QPair<type1, type2>>>(#listtype "<QPair<" #type1 "," #type2 ">>"); \
96 PythonQtConv::registerPythonToMetaTypeConverter(typeId, \
98 PythonQtConv::registerMetaTypeToPythonConverter(typeId, \
100 }

◆ PythonQtRegisterQPairConverter

#define PythonQtRegisterQPairConverter (   type1,
  type2 
)
Value:
{ \
int typeId = qRegisterMetaType<QPair<type1, type2>>("QPair<" #type1 "," #type2 ">"); \
PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonToPair<type1, type2>); \
PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertPairToPython<type1, type2>); \
}

Definition at line 76 of file PythonQtConversion.h.

77 { \
78 int typeId = qRegisterMetaType<QPair<type1, type2>>("QPair<" #type1 "," #type2 ">"); \
79 PythonQtConv::registerPythonToMetaTypeConverter(typeId, PythonQtConvertPythonToPair<type1, type2>); \
80 PythonQtConv::registerMetaTypeToPythonConverter(typeId, PythonQtConvertPairToPython<type1, type2>); \
81 }

◆ PythonQtRegisterToolClassesTemplateConverter

#define PythonQtRegisterToolClassesTemplateConverter (   innertype)

◆ PythonQtRegisterToolClassesTemplateConverterForKnownClass

#define PythonQtRegisterToolClassesTemplateConverterForKnownClass (   innertype)

Typedef Documentation

◆ PythonQtConvertMetaTypeToPythonCB

typedef PyObject * PythonQtConvertMetaTypeToPythonCB(const void *inObject, int metaTypeId)

Definition at line 54 of file PythonQtConversion.h.

◆ PythonQtConvertPythonSequenceToQVariantListCB

typedef QVariant PythonQtConvertPythonSequenceToQVariantListCB(PyObject *inObject)

Definition at line 56 of file PythonQtConversion.h.

◆ PythonQtConvertPythonToMetaTypeCB

typedef bool PythonQtConvertPythonToMetaTypeCB(PyObject *inObject, void *outObject, int metaTypeId, bool strict)

Definition at line 55 of file PythonQtConversion.h.

Function Documentation

◆ PythonQtConvertIntegerMapToPython()

template<class MapType , class T >
PyObject * PythonQtConvertIntegerMapToPython ( const void inMap,
int  metaTypeId 
)

Definition at line 523 of file PythonQtConversion.h.

524{
526 static int innerType = -1;
527 if (innerType == -1) {
532 }
533 if (innerType == QMetaType::UnknownType) {
534 std::cerr << "PythonQtConvertIntegerMapToPython: unknown inner type "
535 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
536 }
537
539 typename MapType::const_iterator t = map->constBegin();
540 PyObject* key;
541 PyObject* val;
542 for (; t != map->constEnd(); t++) {
543 key = PyLong_FromLong(t.key());
546 Py_DECREF(key);
547 Py_DECREF(val);
548 }
549 return result;
550}
struct _object PyObject
static PyObject * convertQtValueToPythonInternal(int type, const void *data)
converts the Qt parameter given in data, interpreting it as a type registered qvariant/meta type,...
static QByteArray getInnerTemplateTypeName(const QByteArray &typeName)
returns the inner type name of a simple template of the form SomeObject<InnerType>
const char * typeNameFromMetaTypeId(int metaTypeId)
Returns the type name from a meta type ID.
int metaTypeIdFromTypeName(const QByteArray &className)
Returns the meta type ID from a type name.

References PythonQtConv::convertQtValueToPythonInternal(), PythonQtMethodInfo::getInnerTemplateTypeName(), PythonQtUtils::metaTypeIdFromTypeName(), PythonQtConvertPairToPython(), and PythonQtUtils::typeNameFromMetaTypeId().

◆ PythonQtConvertListOfKnownClassToPythonList()

template<class ListType , class T >
PyObject * PythonQtConvertListOfKnownClassToPythonList ( const void inList,
int  metaTypeId 
)

Definition at line 327 of file PythonQtConversion.h.

328{
332 if (innerType == nullptr) {
333 std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type for "
334 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
335 }
336 PyObject* result = PyTuple_New(list->size());
337 int i = 0;
338 for (const T& value : *list) {
339 T* newObject = new T(value);
342 wrap->_ownedByPythonQt = true;
344 i++;
345 }
346 return result;
347}
a class that stores all required information about a Qt object (and an optional associated C++ class ...
static QByteArray getInnerListTypeName(const QByteArray &typeName)
returns the inner type name of a simple template or the typename without appended "List".
PyObject * wrapPtr(void *ptr, const QByteArray &name, bool passOwnership=false)
PythonQtClassInfo * getClassInfo(const QMetaObject *meta)
get the class info for a meta object (if available)
static PythonQtPrivate * priv()
get access to internal data (should not be used on the public API, but is used by some C functions)
Definition PythonQt.h:572
a Python wrapper object for Qt objects and C++ objects (that are themselves wrapped by wrapper QObjec...
bool _ownedByPythonQt
flag that stores if the object is owned by pythonQt

References PythonQtInstanceWrapper::_ownedByPythonQt, PythonQtClassInfo::className(), PythonQtPrivate::getClassInfo(), PythonQtMethodInfo::getInnerListTypeName(), PythonQt::priv(), PythonQtUtils::typeNameFromMetaTypeId(), and PythonQtPrivate::wrapPtr().

◆ PythonQtConvertListOfPairToPythonList()

template<class ListType , class T1 , class T2 >
PyObject * PythonQtConvertListOfPairToPythonList ( const void inList,
int  metaTypeId 
)

Definition at line 466 of file PythonQtConversion.h.

467{
469 static int innerType =
471 if (innerType == QMetaType::UnknownType) {
472 std::cerr << "PythonQtConvertListOfPairToPythonList: unknown inner type "
473 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
474 }
475 PyObject* result = PyTuple_New(list->size());
476 int i = 0;
477 typedef const QPair<T1, T2> Pair;
478 for (Pair& value : *list) {
480 PyTuple_SET_ITEM(result, i, object);
481 i++;
482 }
483 return result;
484}
static int getInnerTemplateMetaType(const QByteArray &typeName)
returns the inner type id of a simple template of the form SomeObject<InnerType>

References PythonQtMethodInfo::getInnerTemplateMetaType(), PythonQtConvertPairToPython(), and PythonQtUtils::typeNameFromMetaTypeId().

◆ PythonQtConvertListOfValueTypeToPythonList()

template<class ListType , class T >
PyObject * PythonQtConvertListOfValueTypeToPythonList ( const void inList,
int  metaTypeId 
)

Definition at line 272 of file PythonQtConversion.h.

273{
275 static const int innerType =
277 if (innerType == QMetaType::UnknownType) {
278 std::cerr << "PythonQtConvertListOfValueTypeToPythonList: unknown inner type "
279 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
280 }
281 PyObject* result = PyTuple_New(list->size());
282 int i = 0;
283 for (const T& value : *list) {
285 i++;
286 }
287 return result;
288}

References PythonQtConv::convertQtValueToPythonInternal(), PythonQtMethodInfo::getInnerTemplateMetaType(), and PythonQtUtils::typeNameFromMetaTypeId().

◆ PythonQtConvertPairToPython()

template<class T1 , class T2 >
PyObject * PythonQtConvertPairToPython ( const void *  inPair,
int  metaTypeId 
)

Definition at line 393 of file PythonQtConversion.h.

394{
396 static int innerType1 = -1;
397 static int innerType2 = -1;
398 if (innerType1 == -1) {
404 }
405 if (innerType1 == QMetaType::UnknownType || innerType2 == QMetaType::UnknownType) {
406 std::cerr << "PythonQtConvertPairToPython: unknown inner type " << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId)
407 << std::endl;
408 }
412 return result;
413}

References PythonQtConv::convertQtValueToPythonInternal(), PythonQtMethodInfo::getInnerTemplateTypeName(), PythonQtUtils::metaTypeIdFromTypeName(), and PythonQtUtils::typeNameFromMetaTypeId().

Referenced by PythonQtInstanceWrapper::classInfo(), PythonQtWrapper_QMetaObject::classInfo(), PythonQtWrapper_QMetaObject::classInfoCount(), PythonQtWrapper_QMetaObject::classInfoOffset(), PythonQtStdDecorators::connect(), PythonQtWrapper_QMetaObject::constructor(), PythonQtWrapper_QMetaObject::constructorCount(), PythonQtInstanceWrapper::dynamicClassInfo(), PythonQtWrapper_QMetaObject::enumerator(), PythonQtWrapper_QMetaObject::enumeratorCount(), PythonQtWrapper_QMetaObject::enumeratorOffset(), PythonQtWrapper_QMetaObject::getClassName(), PythonQtWrapper_QMetaObject::indexOfClassInfo(), PythonQtWrapper_QMetaObject::indexOfConstructor(), PythonQtWrapper_QMetaObject::indexOfEnumerator(), PythonQtWrapper_QMetaObject::indexOfMethod(), PythonQtWrapper_QMetaObject::indexOfProperty(), PythonQtWrapper_QMetaObject::indexOfSignal(), PythonQtWrapper_QMetaObject::indexOfSlot(), PythonQtUtils::isPythonClassType(), PythonQtWrapper_QMetaObject::method(), PythonQtWrapper_QMetaObject::methodCount(), PythonQtUtils::methodName(), PythonQtWrapper_QMetaObject::methodOffset(), PythonQtObjectPtr::operator!=(), PythonQtSafeObjectPtr::operator!=(), PythonQtObjectPtr::operator!=(), PythonQtSafeObjectPtr::operator!=(), PythonQtObjectPtr::operator=(), PythonQtSafeObjectPtr::operator=(), PythonQtSafeObjectPtr::operator=(), PythonQtObjectPtr::operator=(), PythonQtObjectPtr::operator=(), PythonQtSafeObjectPtr::operator=(), PythonQtSafeObjectPtr::operator=(), PythonQtObjectPtr::operator=(), PythonQtSafeObjectPtr::operator=(), PythonQtObjectPtr::operator==(), PythonQtSafeObjectPtr::operator==(), PythonQtObjectPtr::operator==(), PythonQtSafeObjectPtr::operator==(), PythonQtInstanceWrapper::passOwnershipToCPP(), PythonQtInstanceWrapper::passOwnershipToPython(), PythonQtWrapper_QMetaObject::property(), PythonQtWrapper_QMetaObject::propertyCount(), PythonQtWrapper_QMetaObject::propertyOffset(), PythonQtConvertIntegerMapToPython(), PythonQtConvertListOfPairToPythonList(), PythonQtConvertPythonListToListOfPair(), PythonQtConvertPythonToIntegerMap(), PythonQtMethodInfo::PythonQtMethodInfo(), PythonQtObjectPtr::PythonQtObjectPtr(), PythonQtObjectPtr::PythonQtObjectPtr(), PythonQtSafeObjectPtr::PythonQtSafeObjectPtr(), PythonQtSafeObjectPtr::PythonQtSafeObjectPtr(), PythonQtSafeObjectPtr::PythonQtSafeObjectPtr(), PythonQtSignalTarget::PythonQtSignalTarget(), PythonQtSlotInfo::PythonQtSlotInfo(), PythonQtSlotInfo::PythonQtSlotInfo(), PythonQtThreadStateSaver::restore(), PythonQtThreadStateSaver::save(), PythonQtSlotInfo::setNextInfo(), PythonQtUtils::signature(), PythonQtWrapper_QMetaObject::static_QMetaObject_checkConnectArgs(), PythonQtStdDecorators::static_QObject_connect(), PythonQtStdDecorators::static_QObject_connect(), PythonQtStdDecorators::static_QObject_disconnect(), PythonQtStdDecorators::static_QObject_disconnect(), PythonQtStdDecorators::static_Qt_qAbs(), PythonQtStdDecorators::static_Qt_qBound(), PythonQtStdDecorators::static_Qt_qCritical(), PythonQtStdDecorators::static_Qt_qDebug(), PythonQtStdDecorators::static_Qt_qFatal(), PythonQtStdDecorators::static_Qt_qFuzzyCompare(), PythonQtStdDecorators::static_Qt_qMax(), PythonQtStdDecorators::static_Qt_qMin(), PythonQtStdDecorators::static_Qt_qrand(), PythonQtStdDecorators::static_Qt_qRound(), PythonQtStdDecorators::static_Qt_qRound64(), PythonQtStdDecorators::static_Qt_qsrand(), PythonQtStdDecorators::static_Qt_qVersion(), PythonQtStdDecorators::static_Qt_qWarning(), PythonQtStdDecorators::static_Qt_SIGNAL(), PythonQtStdDecorators::static_Qt_SLOT(), PythonQtWrapper_QMetaObject::superClass(), PythonQtObjectPtr::takeObject(), PythonQtSafeObjectPtr::takeObject(), PythonQtUtils::typeName(), PythonQtUtils::typeNameFromMetaTypeId(), and PythonQtWrapper_QMetaObject::userProperty().

◆ PythonQtConvertPythonListToListOfKnownClass()

template<class ListType , class T >
bool PythonQtConvertPythonListToListOfKnownClass ( PyObject obj,
void outList,
int  metaTypeId,
bool   
)

Definition at line 350 of file PythonQtConversion.h.

352{
356 if (innerType == nullptr) {
357 std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type for "
358 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
359 }
360 bool result = false;
361 if (PySequence_Check(obj)) {
363 if (count >= 0) {
364 result = true;
366 for (int i = 0; i < count; i++) {
370 bool ok;
371 T* object = (T*)PythonQtConv::castWrapperTo(wrap, innerType->className(), ok);
373 if (ok) {
374 list->push_back(*object);
375 } else {
376 result = false;
377 break;
378 }
379 } else {
381 result = false;
382 break;
383 }
384 }
385 }
386 }
387 return result;
388}
PYTHONQT_EXPORT PyTypeObject PythonQtInstanceWrapper_Type
static void * castWrapperTo(PythonQtInstanceWrapper *wrapper, const QByteArray &className, bool &ok)
cast wrapper to given className if possible

References PythonQtConv::castWrapperTo(), PythonQtClassInfo::className(), PythonQtPrivate::getClassInfo(), PythonQtMethodInfo::getInnerListTypeName(), PythonQt::priv(), PythonQtInstanceWrapper_Type, and PythonQtUtils::typeNameFromMetaTypeId().

◆ PythonQtConvertPythonListToListOfPair()

template<class ListType , class T1 , class T2 >
bool PythonQtConvertPythonListToListOfPair ( PyObject obj,
void outList,
int  metaTypeId,
bool   
)

Definition at line 487 of file PythonQtConversion.h.

489{
491 static int innerType =
493 if (innerType == QMetaType::UnknownType) {
494 std::cerr << "PythonQtConvertPythonListToListOfPair: unknown inner type "
495 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
496 }
497 bool result = false;
498 if (PySequence_Check(obj)) {
500 if (count >= 0) {
501 result = true;
503 for (int i = 0; i < count; i++) {
508 list->push_back(pair);
509 } else {
511 result = false;
512 break;
513 }
514 }
515 }
516 }
517 return result;
518}

References PythonQtMethodInfo::getInnerTemplateMetaType(), PythonQtConvertPairToPython(), and PythonQtUtils::typeNameFromMetaTypeId().

◆ PythonQtConvertPythonListToListOfValueType()

template<class ListType , class T >
bool PythonQtConvertPythonListToListOfValueType ( PyObject obj,
void outList,
int  metaTypeId,
bool   
)

Definition at line 291 of file PythonQtConversion.h.

293{
295 static const int innerType =
297 if (innerType == QMetaType::UnknownType) {
298 std::cerr << "PythonQtConvertPythonListToListOfValueType: unknown inner type "
299 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
300 }
301 bool result = false;
302 if (PySequence_Check(obj)) {
304 if (count >= 0) {
305 result = true;
307 for (int i = 0; i < count; i++) {
309 // this is quite some overhead, but it avoids having another large switch...
312 if (v.isValid()) {
313 list->push_back(qvariant_cast<T>(v));
314 } else {
315 result = false;
316 break;
317 }
318 }
319 }
320 }
321 return result;
322}
static QVariant PyObjToQVariant(PyObject *val, int type=-1)

References PythonQtMethodInfo::getInnerTemplateMetaType(), PythonQtConv::PyObjToQVariant(), and PythonQtUtils::typeNameFromMetaTypeId().

◆ PythonQtConvertPythonToIntegerMap()

template<class MapType , class T >
bool PythonQtConvertPythonToIntegerMap ( PyObject val,
void outMap,
int  metaTypeId,
bool   
)

Definition at line 553 of file PythonQtConversion.h.

554{
556 static int innerType = -1;
557 if (innerType == -1) {
562 }
563 if (innerType == QMetaType::UnknownType) {
564 std::cerr << "PythonQtConvertPythonToIntegerMap: unknown inner type "
565 << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId) << std::endl;
566 }
567 bool result = false;
568 if (PyMapping_Check(val)) {
569 result = true;
571 if (items) {
572 int count = PyList_Size(items);
574 PyObject* key;
576 for (int i = 0; i < count; i++) {
580
581 bool ok;
582 int intKey = PythonQtConv::PyObjGetInt(key, false, ok);
583 // this is quite some overhead, but it avoids having another large switch...
585 if (v.isValid() && ok) {
586 map->insert(intKey, qvariant_cast<T>(v));
587 } else {
588 result = false;
589 break;
590 }
591 }
593 }
594 }
595 return result;
596}
static int PyObjGetInt(PyObject *val, bool strict, bool &ok)
get int from py object

References PythonQtMethodInfo::getInnerTemplateTypeName(), PythonQtUtils::metaTypeIdFromTypeName(), PythonQtConv::PyObjGetInt(), PythonQtConv::PyObjToQVariant(), PythonQtConvertPairToPython(), and PythonQtUtils::typeNameFromMetaTypeId().

◆ PythonQtConvertPythonToPair()

template<class T1 , class T2 >
bool PythonQtConvertPythonToPair ( PyObject obj,
void outPair,
int  metaTypeId,
bool   
)

Definition at line 416 of file PythonQtConversion.h.

417{
419 static int innerType1 = -1;
420 static int innerType2 = -1;
421 if (innerType1 == -1) {
427 }
428 if (innerType1 == QMetaType::UnknownType || innerType2 == QMetaType::UnknownType) {
429 std::cerr << "PythonQtConvertPythonToPair: unknown inner type " << PythonQtUtils::typeNameFromMetaTypeId(metaTypeId)
430 << std::endl;
431 }
432 bool result = false;
433 if (PySequence_Check(obj)) {
435 if (count == 2) {
436 result = true;
438
440 // this is quite some overhead, but it avoids having another large switch...
443 if (v.isValid()) {
444 pair->first = qvariant_cast<T1>(v);
445 } else {
446 return false;
447 }
448
450 // this is quite some overhead, but it avoids having another large switch...
453 if (v.isValid()) {
454 pair->second = qvariant_cast<T2>(v);
455 } else {
456 return false;
457 }
458 }
459 }
460 return result;
461}

References PythonQtMethodInfo::getInnerTemplateTypeName(), PythonQtUtils::metaTypeIdFromTypeName(), PythonQtConv::PyObjToQVariant(), and PythonQtUtils::typeNameFromMetaTypeId().