aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpysideqml
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-10-10 15:47:57 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2023-10-23 12:26:07 +0200
commit624e52a0114a966bd852aeb66b8a1b928d80343b (patch)
treefed19c068ee7e9486ec316bade6b2bb3af6bce97 /sources/pyside6/libpysideqml
parentab2cc5e4056a7f67682584fc0fdf81f183a05906 (diff)
QML registration code: Unify checks for QObject inheritance
Task-number: PYSIDE-2484 Change-Id: Idc006c7c355be5e2f740837ee56b12d64d21f477 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/libpysideqml')
-rw-r--r--sources/pyside6/libpysideqml/pysideqmlregistertype.cpp13
1 files changed, 4 insertions, 9 deletions
diff --git a/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp b/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp
index 42b049c43..940847632 100644
--- a/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp
+++ b/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp
@@ -158,14 +158,9 @@ static int qmlRegisterType(PyObject *pyObj, const ImportData &importData,
{
using namespace Shiboken;
- PyTypeObject *qobjectType = qObjectType();
-
PyTypeObject *pyObjType = reinterpret_cast<PyTypeObject *>(pyObj);
- if (!PySequence_Contains(pyObjType->tp_mro, reinterpret_cast<PyObject *>(qobjectType))) {
- PyErr_Format(PyExc_TypeError, "A type inherited from %s expected, got %s.",
- qobjectType->tp_name, pyObjType->tp_name);
+ if (!isQObjectDerived(pyObjType, true))
return -1;
- }
const QMetaObject *metaObject = PySide::retrieveMetaObject(pyObjType);
Q_ASSERT(metaObject);
@@ -443,9 +438,9 @@ static PyObject *qmlElementMacroHelper(PyObject *pyObj,
PyTypeObject *pyObjType = reinterpret_cast<PyTypeObject *>(pyObj);
if (typeName == nullptr)
typeName = pyObjType->tp_name;
- if (!PySequence_Contains(pyObjType->tp_mro, reinterpret_cast<PyObject *>(qObjectType()))) {
+ if (!PySide::isQObjectDerived(pyObjType, false)) {
PyErr_Format(PyExc_TypeError, "This decorator can only be used with classes inherited from QObject, got %s.",
- typeName);
+ pyObjType->tp_name);
return nullptr;
}
@@ -457,7 +452,7 @@ static PyObject *qmlElementMacroHelper(PyObject *pyObj,
const int result = mode == RegisterMode::Singleton
? PySide::Qml::qmlRegisterSingletonType(pyObj, importData,
typeName, nullptr,
- PySide::isQObjectDerived(pyObjType, false),
+ true /* is QObject */,
false)
: PySide::Qml::qmlRegisterType(pyObj, importData,
mode != RegisterMode::Anonymous ? typeName : nullptr,