Skip to content

Commit 140242d

Browse files
committed
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
1 parent e6453f8 commit 140242d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/PythonQt.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,15 @@ void PythonQtPrivate::registerClass(const QMetaObject* metaobject, const char* p
558558
PythonQtClassInfo* parentInfo = lookupClassInfoAndCreateIfNotPresent(m->superClass()->className());
559559
info->addParentClass(PythonQtClassInfo::ParentClassInfo(parentInfo));
560560
}
561-
} else if (first && module) {
561+
} else if (first && (module || (package && package[0]))) {
562562
// There is a wrapper already, but if we got a module, we want to place the wrapper into that module as well,
563563
// since it might have been placed into "private" earlier on.
564564
// If the wrapper was already added to module before, it is just readded, which does no harm.
565565
PyObject* classWrapper = info->pythonQtClassWrapper();
566566
// AddObject steals a reference, so we need to INCREF
567567
Py_INCREF(classWrapper);
568-
if (PyModule_AddObject(module, info->className(), classWrapper) < 0) {
568+
PyObject* pack = module ? module : packageByName(package); // same logic like in createPythonQtClassWrapper
569+
if (PyModule_AddObject(pack, info->className(), classWrapper) < 0) {
569570
Py_DECREF(classWrapper);
570571
}
571572
}

0 commit comments

Comments
 (0)