From e1649c39e83cb5644f8688122488c6a4eb766aa1 Mon Sep 17 00:00:00 2001 From: Uwe Siems Date: Wed, 30 Apr 2025 15:50:43 +0200 Subject: [PATCH] Fix that registered classes are not added to the designated package if they were implicitly added first (to PythonQt.private), and the explicit register method isn't given a Python module object, only a name. Fixes #260 --- src/PythonQt.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index 8c9ba0f96..4d01a15bb 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -558,14 +558,15 @@ void PythonQtPrivate::registerClass(const QMetaObject* metaobject, const char* p PythonQtClassInfo* parentInfo = lookupClassInfoAndCreateIfNotPresent(m->superClass()->className()); info->addParentClass(PythonQtClassInfo::ParentClassInfo(parentInfo)); } - } else if (first && module) { + } else if (first && (module || (package && package[0]))) { // There is a wrapper already, but if we got a module, we want to place the wrapper into that module as well, // since it might have been placed into "private" earlier on. // If the wrapper was already added to module before, it is just readded, which does no harm. PyObject* classWrapper = info->pythonQtClassWrapper(); // AddObject steals a reference, so we need to INCREF Py_INCREF(classWrapper); - if (PyModule_AddObject(module, info->className(), classWrapper) < 0) { + PyObject* pack = module ? module : packageByName(package); // same logic like in createPythonQtClassWrapper + if (PyModule_AddObject(pack, info->className(), classWrapper) < 0) { Py_DECREF(classWrapper); } }