From 0b14472ff76ab954a02f2d2d33f32f8fdb906ba3 2009-06-23 13:40:22 From: florianlink Date: 2009-06-23 13:40:22 Subject: [PATCH] - fixed support for QList* (which occured with QObjectList* return values) - improved children() std decorator to use QObjectList as well - improved error handling on deleted objects git-svn-id: svn://svn.code.sf.net/p/pythonqt/code/trunk@113 ea8d5007-eb21-0410-b261-ccb3ea6e24a9 --- diff --git a/src/PythonQtConversion.cpp b/src/PythonQtConversion.cpp index 6967359..b78f1d7 100644 --- a/src/PythonQtConversion.cpp +++ b/src/PythonQtConversion.cpp @@ -80,11 +80,16 @@ PyObject* PythonQtConv::ConvertQtValueToPython(const PythonQtMethodInfo::Paramet } else if ((info.typeId == PythonQtMethodInfo::Unknown || info.typeId >= QMetaType::User) && info.name.startsWith("QList<")) { // it is a QList template: - // (TODO: check what happens if this is a pointer type?!) QByteArray innerType = info.name.mid(6,info.name.length()-7); if (innerType.endsWith("*")) { innerType.truncate(innerType.length()-1); - return ConvertQListOfPointerTypeToPythonList((QList*)data, innerType); + QList* listPtr; + if (info.isPointer) { + listPtr = *((QList**)data); + } else { + listPtr = (QList*)data; + } + return ConvertQListOfPointerTypeToPythonList(listPtr, innerType); } } diff --git a/src/PythonQtSlot.cpp b/src/PythonQtSlot.cpp index 6d63f47..ee4ff14 100644 --- a/src/PythonQtSlot.cpp +++ b/src/PythonQtSlot.cpp @@ -185,7 +185,13 @@ PyObject *PythonQtSlotFunction_Call(PyObject *func, PyObject *args, PyObject *kw PythonQtSlotInfo* info = f->m_ml; if (PyObject_TypeCheck(f->m_self, &PythonQtInstanceWrapper_Type)) { PythonQtInstanceWrapper* self = (PythonQtInstanceWrapper*) f->m_self; - return PythonQtSlotFunction_CallImpl(self->classInfo(), self->_obj, info, args, kw, self->_wrappedPtr); + if (!info->isClassDecorator() && (self->_obj==NULL && self->_wrappedPtr==NULL)) { + QString error = QString("Trying to call '") + f->m_ml->slotName() + "' on a destroyed " + self->classInfo()->className() + " object"; + PyErr_SetString(PyExc_ValueError, error.toLatin1().data()); + return NULL; + } else { + return PythonQtSlotFunction_CallImpl(self->classInfo(), self->_obj, info, args, kw, self->_wrappedPtr); + } } else if (f->m_self->ob_type == &PythonQtClassWrapper_Type) { PythonQtClassWrapper* type = (PythonQtClassWrapper*) f->m_self; if (info->isClassDecorator()) { @@ -198,6 +204,11 @@ PyObject *PythonQtSlotFunction_Call(PyObject *func, PyObject *args, PyObject *kw if (PyObject_TypeCheck(firstArg, (PyTypeObject*)&PythonQtInstanceWrapper_Type) && ((PythonQtInstanceWrapper*)firstArg)->classInfo()->inherits(type->classInfo())) { PythonQtInstanceWrapper* self = (PythonQtInstanceWrapper*)firstArg; + if (!info->isClassDecorator() && (self->_obj==NULL && self->_wrappedPtr==NULL)) { + QString error = QString("Trying to call '") + f->m_ml->slotName() + "' on a destroyed " + self->classInfo()->className() + " object"; + PyErr_SetString(PyExc_ValueError, error.toLatin1().data()); + return NULL; + } // strip the first argument... PyObject* newargs = PyTuple_GetSlice(args, 1, argc); PyObject* result = PythonQtSlotFunction_CallImpl(self->classInfo(), self->_obj, info, newargs, kw, self->_wrappedPtr); diff --git a/src/PythonQtStdDecorators.cpp b/src/PythonQtStdDecorators.cpp index 3a92abc..2a5fdee 100644 --- a/src/PythonQtStdDecorators.cpp +++ b/src/PythonQtStdDecorators.cpp @@ -144,14 +144,9 @@ void PythonQtStdDecorators::setParent(QObject* o, QObject* parent) o->setParent(parent); } -QVariantList PythonQtStdDecorators::children(QObject* o) +const QObjectList* PythonQtStdDecorators::children(QObject* o) { - QVariantList v; - QListIterator it(o->children()); - while (it.hasNext()) { - v << qVariantFromValue(it.next()); - } - return v; + return &o->children(); } QString PythonQtStdDecorators::tr(QObject* obj, const QByteArray& text, const QByteArray& ambig, int n) diff --git a/src/PythonQtStdDecorators.h b/src/PythonQtStdDecorators.h index e5cf879..7ca327b 100644 --- a/src/PythonQtStdDecorators.h +++ b/src/PythonQtStdDecorators.h @@ -70,7 +70,7 @@ public slots: QObject* parent(QObject* o); void setParent(QObject* o, QObject* parent); - QVariantList children(QObject* o); + const QObjectList* children(QObject* o); double static_Qt_qAbs(double a) { return qAbs(a); } double static_Qt_qBound(double a,double b,double c) { return qBound(a,b,c); }