aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Herrmann <adrian.herrmann@qt.io>2024-03-07 15:59:28 +0100
committerAdrian Herrmann <adrian.herrmann@qt.io>2024-03-11 12:20:41 +0100
commite8b8ca6846530ceabcfb713aaa2804da18711eda (patch)
treea9da2b932cc9df37221fcb138e2bb61f552db7e5
parent8afb258a4177fe8eed2c569a9a7245f555ac5901 (diff)
Fix connect() for QObject callables
The addition of the QObject.connect() overload that takes a context resulted in an automatic overload ordering that prevented the right overload from ever being called if the callable was a QObject. Set a manual order to fix this. Pick-to: 6.6 Fixes: PYSIDE-2627 Change-Id: I863f6caaed926b48bc412a29541c1d431ebd50b0 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--sources/pyside6/PySide6/QtCore/typesystem_core_common.xml23
-rw-r--r--sources/pyside6/tests/signals/CMakeLists.txt1
-rw-r--r--sources/pyside6/tests/signals/qobject_callable_connect_test.py45
3 files changed, 62 insertions, 7 deletions
diff --git a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
index 371055605..ca932edf2 100644
--- a/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
+++ b/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml
@@ -1770,14 +1770,23 @@
</modify-argument>
<modify-argument index="1" pyi-type="Optional[PySide6.QtCore.QObject]"/>
</modify-function>
- <modify-function signature="connect(const QObject*,const char*,const char*,Qt::ConnectionType)const">
+ <!-- Manual overload order fixes PYSIDE-2627
+
+ The addition of the qobject-connect-4-context overload resulted in an
+ automatic overload ordering that prevented the right overload from
+ ever being called if the callable was a QObject. Set a manual order to
+ fix this. -->
+ <modify-function signature="connect(const QObject*,const char*,const char*,Qt::ConnectionType)const"
+ overload-number="0">
<inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qobject-connect-1"/>
</modify-function>
<!-- static version -->
- <modify-function signature="connect(const QObject*,QMetaMethod,const QObject*,QMetaMethod,Qt::ConnectionType)">
+ <modify-function signature="connect(const QObject*,QMetaMethod,const QObject*,QMetaMethod,Qt::ConnectionType)"
+ overload-number="1">
<inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qobject-connect-2"/>
</modify-function>
- <modify-function signature="connect(const QObject*,const char*,const QObject*,const char*,Qt::ConnectionType)">
+ <modify-function signature="connect(const QObject*,const char*,const QObject*,const char*,Qt::ConnectionType)"
+ overload-number="2">
<modify-argument index="5">
<rename to="type"/>
</modify-argument>
@@ -1785,20 +1794,20 @@
</modify-function>
<inject-code class="native" position="beginning" file="../glue/qtcore.cpp" snippet="qobject-connect"/>
<add-function signature="connect(const QObject*@sender@,const char*@signal@,PyCallable*@functor@,Qt::ConnectionType@type@=Qt::AutoConnection)"
- return-type="QMetaObject::Connection" static="yes">
+ return-type="QMetaObject::Connection" static="yes" overload-number="3">
<inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qobject-connect-4"/>
</add-function>
<add-function signature="connect(const QObject*@sender@,const char*@signal@,const QObject*@context@,PyCallable*@functor@,Qt::ConnectionType@type@=Qt::AutoConnection)"
- return-type="QMetaObject::Connection" static="yes">
+ return-type="QMetaObject::Connection" static="yes" overload-number="4">
<inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qobject-connect-4-context"/>
</add-function>
<!-- static version -->
<add-function signature="connect(const char*@signal@,PyCallable*@functor@,Qt::ConnectionType@type@=Qt::AutoConnection)"
- return-type="QMetaObject::Connection">
+ return-type="QMetaObject::Connection" overload-number="5">
<inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qobject-connect-5"/>
</add-function>
<add-function signature="connect(const char*@signal@,const QObject*@receiver@,const char*@method@,Qt::ConnectionType@type@=Qt::AutoConnection)"
- return-type="QMetaObject::Connection">
+ return-type="QMetaObject::Connection" overload-number="6">
<inject-code class="target" position="beginning" file="../glue/qtcore.cpp" snippet="qobject-connect-6"/>
</add-function>
diff --git a/sources/pyside6/tests/signals/CMakeLists.txt b/sources/pyside6/tests/signals/CMakeLists.txt
index 96946c002..ff342adc7 100644
--- a/sources/pyside6/tests/signals/CMakeLists.txt
+++ b/sources/pyside6/tests/signals/CMakeLists.txt
@@ -16,6 +16,7 @@ PYSIDE_TEST(leaking_signal_test.py)
PYSIDE_TEST(multiple_connections_gui_test.py)
PYSIDE_TEST(multiple_connections_test.py)
PYSIDE_TEST(pysignal_test.py)
+PYSIDE_TEST(qobject_callable_connect_test.py)
PYSIDE_TEST(qobject_destroyed_test.py)
PYSIDE_TEST(qobject_receivers_test.py)
PYSIDE_TEST(qobject_sender_test.py)
diff --git a/sources/pyside6/tests/signals/qobject_callable_connect_test.py b/sources/pyside6/tests/signals/qobject_callable_connect_test.py
new file mode 100644
index 000000000..a7a26d6f5
--- /dev/null
+++ b/sources/pyside6/tests/signals/qobject_callable_connect_test.py
@@ -0,0 +1,45 @@
+# Copyright (C) 2024 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from PySide6.QtCore import QObject, Signal
+
+
+class Emitter(QObject):
+ sig = Signal(int)
+
+
+class CallableObject(QObject):
+ called = False
+ x = 0
+
+ def __call__(self, x: int):
+ self.called = True
+ self.x = x
+
+
+class QObjectCallableConnectTest(unittest.TestCase):
+ '''Test case for QObject.connect() when the callable is also a QObject.'''
+
+ def testCallableConnect(self):
+ emitter = Emitter()
+ obj = CallableObject()
+ x = 1
+
+ emitter.sig.connect(obj)
+ emitter.sig.emit(x)
+
+ self.assertTrue(obj.called)
+ self.assertEqual(obj.x, x)
+
+
+if __name__ == '__main__':
+ unittest.main()