Important: Please read the Qt Code of Conduct -

Pyside, declarative: Returning a value from a slot

  • Hi,

    Been playing with python/QML and slots returning values, but things dont seem to work well when you do something like:

    class Communicate(QtCore.QObject):
    def init(self):
    self.r = 0
    self.s = "heloo"

    def val(self):
    v = self.r + 10
    return v

    def giveit(self):
    return self.s

    and then in the QML :
    @helloText.text = getstuffdone.val()@

    the Value is always shows up 1
    and it is same for returning strings. The returned string is empty.

    and I also checked with the pyside examples and it does same issue (see example qmltopy2), the rotation does not pick up.

    any idea how to make it work?

  • oo and in my i aslo do :
    if name == "main":
    import sys

    initiate the main QML application

    app = QtGui.QApplication(sys.argv)


    view = QtDeclarative.QDeclarativeView()

    getstuffdone = Communicate()

    timer = QtCore.QTimer()
    context = view.rootContext()

    context.setContextProperty("getstuffdone", getstuffdone)




  • hi adhorn, this was fixed on PySide git version. A new version with this and others bugs fixes will be released soon.

  • I guess the not working pytoqml1 example is the same case, right? If not, I'll provide more details. Basically the problem is, that Python doesn't see QML/JavaScript functions and raises and error if you to try to execute them.

Log in to reply