From 292a8e2426b14f98f4863dc58b5bf363ca97e748 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 4 Oct 2021 16:38:36 +0200 Subject: PySide6: Fix QObject.property() for QFlag types QObject::property() returns a QVariant for whose type a shiboken converter is retrieved by name (QVariant::typeName()). This fails for QFlags types since QVariant::typeName() returns the fully expanded name QFlag. Register the flags converter under that name, too, to fix this. Pick-to: 6.2 Fixes: PYSIDE-1673 Change-Id: I23e83da34b82196d76b78fa44f67647da65737c8 Reviewed-by: Christian Tismer --- sources/pyside6/tests/QtWidgets/qlabel_test.py | 7 +++++++ sources/shiboken6/generator/shiboken/cppgenerator.cpp | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/sources/pyside6/tests/QtWidgets/qlabel_test.py b/sources/pyside6/tests/QtWidgets/qlabel_test.py index b8bbb2902..e4b4e9f21 100644 --- a/sources/pyside6/tests/QtWidgets/qlabel_test.py +++ b/sources/pyside6/tests/QtWidgets/qlabel_test.py @@ -37,6 +37,7 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from init_paths import init_test_paths init_test_paths(True) +from PySide6.QtCore import Qt from PySide6.QtGui import QPixmap from PySide6.QtWidgets import QLabel from shiboken6 import Shiboken @@ -85,6 +86,12 @@ class QLabelTest(UsesQApplication): self.assertTrue(all(Shiboken.getCppPointer(o) != ret_p_addr for o in Shiboken.getAllValidWrappers())) + # Test for PYSIDE-1673, QObject.property() returning a QFlags<> property. + def testQObjectProperty(self): + a = self.label.property("alignment") + self.assertEqual(type(a), Qt.Alignment) + print("alignment=", a) + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 5db3d82e3..4af72beda 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -4108,6 +4108,14 @@ void CppGenerator::writeEnumConverterInitialization(TextStream &s, const TypeEnt else break; } + if (flags) { + // PYSIDE-1673: Also register "QFlags" purely for + // the purpose of finding the converter by QVariant::typeName() + // in the QVariant conversion code. + s << "Shiboken::Conversions::registerConverterName(converter, \"" + << flags->name() << "\");\n"; + } + } s << "}\n"; -- cgit v1.2.3