aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-04-30 12:56:17 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-05-06 10:57:23 +0200
commit9fcc3066412e23e92eb05d30dcad858f8ca1cd90 (patch)
tree97eb9cc1f12651621b7dbdf4207716317080b4df
parent4cdaaffbb58560dc1adbcf9de471ff4fb7d7f235 (diff)
Fix polymorphic discovery to work without names
In newObjectWithHeuristics(), try the type discovery graph check for the inherited class also in case the typeName is identical to the base name (which means typeid() was not able to do resolution based on virtual tables). Change-Id: Ia8912a4860a580418438f659b7a854647657ab9a Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/pyside6/tests/QtGui/qbrush_test.py10
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.cpp6
2 files changed, 13 insertions, 3 deletions
diff --git a/sources/pyside6/tests/QtGui/qbrush_test.py b/sources/pyside6/tests/QtGui/qbrush_test.py
index 800e6f072..69262328b 100644
--- a/sources/pyside6/tests/QtGui/qbrush_test.py
+++ b/sources/pyside6/tests/QtGui/qbrush_test.py
@@ -13,7 +13,7 @@ from init_paths import init_test_paths
init_test_paths(False)
from PySide6.QtCore import Qt
-from PySide6.QtGui import QColor, QBrush
+from PySide6.QtGui import QColor, QBrush, QConicalGradient
from helper.usesqapplication import UsesQApplication
@@ -30,6 +30,14 @@ class Constructor(UsesQApplication):
obj = QBrush(Qt.blue)
self.assertEqual(obj.color(), Qt.blue)
+ def testGradient(self):
+ """Test type discovery on class hierarchies with non-virtual
+ destructors by specifying a polymorphic-id-expression without
+ polymorphic-name-function."""
+ gradient = QConicalGradient()
+ brush = QBrush(gradient)
+ self.assertEqual(type(brush.gradient()), type(gradient))
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp
index 61e824f64..823078735 100644
--- a/sources/shiboken6/libshiboken/basewrapper.cpp
+++ b/sources/shiboken6/libshiboken/basewrapper.cpp
@@ -1441,8 +1441,10 @@ static PyObject *newObjectWithHeuristicsHelper(PyTypeObject *instanceType,
void *cptr,
bool hasOwnership)
{
- // Try to find the exact type of cptr.
- if (exactType == nullptr) {
+ // Try to find the exact type of cptr. For hierarchies with
+ // non-virtual destructors, typeid() will return the base name.
+ // Try type discovery in these cases.
+ if (exactType == nullptr || exactType == instanceType) {
auto resolved = BindingManager::instance().findDerivedType(cptr, instanceType);
if (resolved.first != nullptr) {
exactType = resolved.first;