aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-10-04 16:38:36 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-10-05 17:02:34 +0200
commit292a8e2426b14f98f4863dc58b5bf363ca97e748 (patch)
tree49447957883237e6881c568b889b6f5a45ce42b1
parent2bdb0154c9409169f1b1d143cb328b741fe09568 (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. Pick-to: 6.2 Fixes: PYSIDE-1673 Change-Id: I23e83da34b82196d76b78fa44f67647da65737c8 Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/pyside6/tests/QtWidgets/qlabel_test.py7
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp8
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 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<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";