Я пытаюсь воспроизвести приведенный ниже пример, используя PySide2.
https://evileg.com/en/post/242/
Но поскольку PySide2 не поддерживает отправку сигнала с именованным параметром в QML, я понятия не имею, как это сделать с помощью PySide2?
Вот мой код
main.py
from PySide2.QtGui import QGuiApplication
from PySide2.QtQml import QQmlApplicationEngine
from PySide2.QtCore import QObject, Signal, Slot, Property
class Calculator(QObject):
def __init__(self):
QObject.__init__(self)
sumResult = Signal(int)
subResult = Signal(int)
@Slot(int, int)
def sum(self, arg1, arg2):
self.sumResult.emit(arg1 + arg2)
@Slot(int, int)
def sub(self, arg1, arg2):
self.subResult.emit(arg1 - arg2)
if __name__ == "__main__":
import sys
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
calculator = Calculator()
engine.rootContext().setContextProperty("calculator", calculator)
engine.load("/code/QML/calc.qml")
engine.quit.connect(app.quit)
sys.exit(app.exec_())