From 31700bd9f8fe795cb782ac273026e47950e854c4 2013-01-29 08:50:21 From: florianlink Date: 2013-01-29 08:50:21 Subject: [PATCH] improved conversion (merged from MeVisLab PythonQt) git-svn-id: svn://svn.code.sf.net/p/pythonqt/code/trunk@238 ea8d5007-eb21-0410-b261-ccb3ea6e24a9 --- diff --git a/src/PythonQtConversion.cpp b/src/PythonQtConversion.cpp index c1d6888..b5315ab 100644 --- a/src/PythonQtConversion.cpp +++ b/src/PythonQtConversion.cpp @@ -76,7 +76,13 @@ PyObject* PythonQtConv::ConvertQtValueToPython(const PythonQtMethodInfo::Paramet return Py_None; } else if ((info.pointerCount == 1) && (info.typeId == QMetaType::Char)) { // a char ptr will probably be a null terminated string, so we support that: - return PyString_FromString(*((char**)data)); + char* charPtr = *((char**)data); + if (charPtr) { + return PyString_FromString(charPtr); + } else { + Py_INCREF(Py_None); + return Py_None; + } } else if ((info.typeId == PythonQtMethodInfo::Unknown || info.typeId >= QMetaType::User) && info.name.startsWith("QList<")) { // it is a QList template: @@ -371,7 +377,11 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i ptr = object; } } else { - // not matching + // not matching, maybe a PyObject*? + if (info.name == "PyObject" && info.pointerCount==1) { + // handle low level PyObject directly + PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_ptrStorage, void*, obj, ptr); + } } } else if (info.pointerCount == 1) { // a pointer @@ -885,14 +895,14 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) // no special type requested if (val->ob_type==&PyString_Type || val->ob_type==&PyUnicode_Type) { type = QVariant::String; + } else if (val == Py_False || val == Py_True) { + type = QVariant::Bool; } else if (PyObject_TypeCheck(val, &PyInt_Type)) { type = QVariant::Int; } else if (val->ob_type==&PyLong_Type) { type = QVariant::LongLong; } else if (val->ob_type==&PyFloat_Type) { type = QVariant::Double; - } else if (val == Py_False || val == Py_True) { - type = QVariant::Bool; } else if (PyObject_TypeCheck(val, &PythonQtInstanceWrapper_Type)) { PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)val; // c++ wrapper, check if the class names of the c++ objects match