diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-10-04 16:38:36 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-10-05 19:26:19 +0000 |
commit | 242300c1cd9d0b0eca6114064a24e87b6ea51ab7 (patch) | |
tree | 34a0b35f3be44f817b385207e919890f68ff2973 | |
parent | a4f505e5274a58477a1df4e9ca4b9c25f50e1a7d (diff) |
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<Enum>. Register the flags converter under that name, too,
to fix this.
Fixes: PYSIDE-1673
Change-Id: I23e83da34b82196d76b78fa44f67647da65737c8
Reviewed-by: Christian Tismer <tismer@stackless.com>
(cherry picked from commit 292a8e2426b14f98f4863dc58b5bf363ca97e748)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | sources/pyside6/tests/QtWidgets/qlabel_test.py | 7 | ||||
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 8 |
2 files changed, 15 insertions, 0 deletions
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 e1c6eda73..473c79c25 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -4117,6 +4117,14 @@ void CppGenerator::writeEnumConverterInitialization(TextStream &s, const TypeEnt else break; } + if (flags) { + // PYSIDE-1673: Also register "QFlags<Class::Option>" 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"; |