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):
    super(Communicate,self).init()
    self.r = 0
    self.s = "heloo"

    @QtCore.Slot(result=int)
    def val(self):
    v = self.r + 10
    return v

    @QtCore.Slot(result=str)
    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 main.py i aslo do :
    @
    if name == "main":
    import sys

    initiate the main QML application

    app = QtGui.QApplication(sys.argv)

    myClass

    view = QtDeclarative.QDeclarativeView()

    getstuffdone = Communicate()

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

    context.setContextProperty("getstuffdone", getstuffdone)

    view.setSource(QtCore.QUrl('book.qml'))

    view.show()

    execute

    sys.exit(app.exec_())
    @



  • 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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.