From cc3f68e0126dde5d2f932a81230cd092f3304fdf Mon Sep 17 00:00:00 2001 From: Uwe Siems Date: Thu, 28 Aug 2025 16:28:55 +0200 Subject: [PATCH] The algorithm that derived the package name for the init code... did not really work well for package names that didn't start with com.trolltech., thus we modified this part a little bit to suit our needs --- generator/setupgenerator.cpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/generator/setupgenerator.cpp b/generator/setupgenerator.cpp index d23e89d0d..7fcc582c5 100644 --- a/generator/setupgenerator.cpp +++ b/generator/setupgenerator.cpp @@ -218,6 +218,18 @@ static void addListRegistration(AbstractMetaType::shared_pointer type, QSet 0) { + p[0] = p[0].toUpper(); + } + } + return parts; + } +} + void SetupGenerator::generate() { AbstractMetaClassList classes_with_polymorphic_id; @@ -245,9 +257,19 @@ void SetupGenerator::generate() QString packKey = ShellGenerator::toFileNameBase(pack.key()); QString packName = packKey; - QString qtPackageName = "Qt" + pack.key().split('.').back().split('_').front(); - bool isBuiltin = packKey.endsWith("_builtin"); - QString initName = qtPackageName + (isBuiltin ? "Builtin" : ""); + QString packageName = pack.key(); + QString trolltechPrefix = "com.trolltech."; + if (packageName.startsWith(trolltechPrefix)) { + // remove this prefix + packageName = packageName.mid(trolltechPrefix.length()); + } + packageName = capitalize(packageName.split('.')).join(""); + bool isBuiltin = packageName.endsWith("_builtin"); + if (isBuiltin) { + // remove trailing _builtin from packageName: + packageName = packageName.left(packageName.length() - 8); + } + QString initName = packageName + (isBuiltin ? "Builtin" : ""); { QString fileName(packName + "/" + packKey + "_init.cpp"); @@ -336,12 +358,12 @@ void SetupGenerator::generate() operatorCodes = "0"; } if (cls->isQObject()) { - s << "PythonQt::priv()->registerClass(&" << cls->qualifiedCppName() << "::staticMetaObject, \"" << qtPackageName <<"\", PythonQtCreateObjectname() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl; + s << "PythonQt::priv()->registerClass(&" << cls->qualifiedCppName() << "::staticMetaObject, \"" << packageName <<"\", PythonQtCreateObjectname() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl; } else if (cls->isGlobalNamespace()) { - s << "PythonQt::priv()->registerGlobalNamespace(\"" << cls->qualifiedCppName() << "\", \"" << qtPackageName << "\", PythonQtCreateObjectname() << ">, PythonQtWrapper_" << cls->name() << "::staticMetaObject, module); " << endl; + s << "PythonQt::priv()->registerGlobalNamespace(\"" << cls->qualifiedCppName() << "\", \"" << packageName << "\", PythonQtCreateObjectname() << ">, PythonQtWrapper_" << cls->name() << "::staticMetaObject, module); " << endl; } else { QString baseName = cls->baseClass()?cls->baseClass()->qualifiedCppName():""; - s << "PythonQt::priv()->registerCPPClass(\""<< cls->qualifiedCppName() << "\", \"" << baseName << "\", \"" << qtPackageName <<"\", PythonQtCreateObjectname() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl; + s << "PythonQt::priv()->registerCPPClass(\""<< cls->qualifiedCppName() << "\", \"" << baseName << "\", \"" << packageName <<"\", PythonQtCreateObjectname() << ">" << shellCreator << ", module, " << operatorCodes <<");" << endl; } for (AbstractMetaClass* interface : cls->interfaces()) { // the interface might be our own class... (e.g. QPaintDevice)