PyQt slot return value

  • Any help with this would be appreciated, including hints on how to debug further.

    The pyqtSlot decorator takes a result as one of the parameters. However, I'm lost as to how to use it. Here's code to replicate my minimal problem.

    import sys

    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject

    class TestSlot( QObject ):

    newTrigger = pyqtSignal()
    def __init__( self ):
        super( TestSlot, self ).__init__()
    def doIt( self ):
        print "Call: doIt"
        test = self.newTrigger.emit()
        print "emit return val: %s" % test
    @pyqtSlot( result = str )
    def myTestFunction( self ):
        print "Call: myTestFunction"
        result = "Here's a return value"
        return "Even returning a string"

    app = QApplication( sys.argv )

    w = TestSlot()
    w.newTrigger.connect( w.myTestFunction )

    the_return_val = w.doIt()
    print "Doit return value: %s" % the_return_val

    The results from this are:
    @➜ python
    Call: doIt
    Call: myTestFunction
    emit return val: None
    Doit return value: None

    Where is my return value?

  • @pyqtSlot( result = str ) is only for the C++ declaration.
    you can not use the return value with an emit Event. ;-(


Log in to reply

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