Skip to content

Commit eeb7da2

Browse files
author
florianlink
committed
improved conversion (merged from MeVisLab PythonQt)
git-svn-id: https://pythonqt.svn.sourceforge.net/svnroot/pythonqt/trunk@238 ea8d5007-eb21-0410-b261-ccb3ea6e24a9
1 parent 03303a3 commit eeb7da2

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/PythonQtConversion.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ PyObject* PythonQtConv::ConvertQtValueToPython(const PythonQtMethodInfo::Paramet
7676
return Py_None;
7777
} else if ((info.pointerCount == 1) && (info.typeId == QMetaType::Char)) {
7878
// a char ptr will probably be a null terminated string, so we support that:
79-
return PyString_FromString(*((char**)data));
79+
char* charPtr = *((char**)data);
80+
if (charPtr) {
81+
return PyString_FromString(charPtr);
82+
} else {
83+
Py_INCREF(Py_None);
84+
return Py_None;
85+
}
8086
} else if ((info.typeId == PythonQtMethodInfo::Unknown || info.typeId >= QMetaType::User) &&
8187
info.name.startsWith("QList<")) {
8288
// it is a QList template:
@@ -371,7 +377,11 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i
371377
ptr = object;
372378
}
373379
} else {
374-
// not matching
380+
// not matching, maybe a PyObject*?
381+
if (info.name == "PyObject" && info.pointerCount==1) {
382+
// handle low level PyObject directly
383+
PythonQtValueStorage_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,global_ptrStorage, void*, obj, ptr);
384+
}
375385
}
376386
} else if (info.pointerCount == 1) {
377387
// a pointer
@@ -885,14 +895,14 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
885895
// no special type requested
886896
if (val->ob_type==&PyString_Type || val->ob_type==&PyUnicode_Type) {
887897
type = QVariant::String;
898+
} else if (val == Py_False || val == Py_True) {
899+
type = QVariant::Bool;
888900
} else if (PyObject_TypeCheck(val, &PyInt_Type)) {
889901
type = QVariant::Int;
890902
} else if (val->ob_type==&PyLong_Type) {
891903
type = QVariant::LongLong;
892904
} else if (val->ob_type==&PyFloat_Type) {
893905
type = QVariant::Double;
894-
} else if (val == Py_False || val == Py_True) {
895-
type = QVariant::Bool;
896906
} else if (PyObject_TypeCheck(val, &PythonQtInstanceWrapper_Type)) {
897907
PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)val;
898908
// c++ wrapper, check if the class names of the c++ objects match

0 commit comments

Comments
 (0)