Important: Please read the Qt Code of Conduct -

Passing arguments from PySide2 to QML.

  • Hi all,
    I'm current trying to figure out how to use Python with QT QML. So far I have been successful in passing info from QML to python with no problems, however after much searching and frustration I have not been able to go from Python to QML.

    So I'm currently using
    Python code:
    valfeedback = Signal(float, name = "pos")
    Connections {
    target: Manager

        onValfeedback: {
            label.text = Manager.pos


    But this just complains about Error: Cannot assign [undefined] to QString But I'm not sure how it is supposed to be defined???

    I'm sure that I'm missing something really simple but have spent hours on this with no results - Please help........

    My sample code below..

    import sys
    import os

    from PySide2.QtCore import Qt, QObject, Signal, Slot, Property
    from PySide2.QtGui import QGuiApplication
    from PySide2.QtQml import QQmlApplicationEngine

    class Manager(QObject):

    def __init__(self):
        self.m_currentValue = 3.4
        self.m_buttonValue = 0
        self.labelInfo = "47"
    valfeedback = Signal(float, name = "pos")
    def currentValue(self):
       return self.m_currentValue
    def setCurrentValue(self, val):
        if self.m_currentValue == val:
        self.m_currentValue = val
    def buttonValue(self):
        return self.m_buttonValue
    def setButtonValue(self, val):
        self.m_buttonValue = val

    if name == "main":
    os.environ["QT_QUICK_CONTROLS_STYLE"] = "Material"
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    manager = Manager()
    ctx = engine.rootContext()
    ctx.setContextProperty("Manager", manager)
    if not engine.rootObjects():


    import QtQuick 2.10
    import QtQuick.Controls 2.3
    import QtQuick.Layouts 1.0

    ApplicationWindow {
    id: applicationWindow

    title: qsTr("Test Invoke")
    visible: true
    width: 600
    height: 500
    Slider {
        id: slider
        x: 78
        y: 330
        width: 444
        height: 40
        value: 0.5
        property bool updateValueWhileDragging: false
        onMoved: Manager.currentValue = value
    Button {
        id: button
        x: 250
        y: 230
        text: qsTr("Press Me Please")
        checkable: true
        onPressed: Manager.buttonValue = 1
    Label {
        id: label
        x: 37
        y: 65
        horizontalAlignment: Text.AlignHCenter
        font.pointSize: 35
    Connections {
        target: Manager
        onValfeedback: {
            label.text = Manager.pos


Log in to reply