##// END OF EJS Templates
added support for return by value of classes that are NOT registered with QMetaType but which have a default constructor decorator...
florianlink -
r46:1db88b846b4a
parent child
Show More
@@ -134,6 +134,20 bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObj
134 134 if (!directReturnValuePointer) {
135 135 // create empty default value for the return value
136 136 argList[0] = PythonQtConv::CreateQtReturnValue(returnValueParam);
137 if (argList[0]==NULL) {
138 // return value could not be created, maybe we have a registered class with a default constructor, so that we can construct the pythonqt wrapper object and
139 // pass its internal pointer
140 PythonQtClassInfo* info = PythonQt::priv()->getClassInfo(returnValueParam.name);
141 if (info && info->pythonQtClassWrapper()) {
142 PyObject* emptyTuple = PyTuple_New(0);
143 // 1) default construct an empty object as python object (owned by PythonQt), by calling the meta class with empty arguments
144 result = PyObject_Call((PyObject*)info->pythonQtClassWrapper(), emptyTuple, NULL);
145 if (result) {
146 argList[0] = ((PythonQtInstanceWrapper*)result)->_wrappedPtr;
147 }
148 Py_DECREF(emptyTuple);
149 }
150 }
137 151 } else {
138 152 // we can use our pointer directly!
139 153 argList[0] = directReturnValuePointer;
@@ -150,13 +164,16 bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObj
150 164 result = NULL;
151 165 } else {
152 166 if (!returnValueIsEnum) {
153 result = PythonQtConv::ConvertQtValueToPython(returnValueParam, argList[0]);
167 // the resulting object maybe present already, because we created it above at 1)...
168 if (!result) {
169 result = PythonQtConv::ConvertQtValueToPython(returnValueParam, argList[0]);
170 }
154 171 } else {
155 172 result = PyInt_FromLong(*((unsigned int*)argList[0]));
156 173 }
157 174 }
158 175 } else {
159 QString e = QString("Called ") + info->fullSignature() + ", return type '" + returnValueParam.name + "' is ignored because it is unknown to PythonQt. Probaby you should register it using qRegisterMetaType().";
176 QString e = QString("Called ") + info->fullSignature() + ", return type '" + returnValueParam.name + "' is ignored because it is unknown to PythonQt. Probably you should register it using qRegisterMetaType() or add a default constructor decorator to the class.";
160 177 PyErr_SetString(PyExc_ValueError, e.toLatin1().data());
161 178 result = NULL;
162 179 }
General Comments 0
You need to be logged in to leave comments. Login now