Cannot use a signal with a str parameter for QState.addTransition under PySide



  • Hello everyone,

    I have some problems using the HSM framework under PySide. I gave a minimal not working example below.

    @
    from PySide import QtCore, QtGui
    import sys

    class MyMainWindow(QtGui.QMainWindow):
    test_signal1 = QtCore.Signal()
    test_signal2 = QtCore.Signal(int)
    test_signal3 = QtCore.Signal(str)
    def init(self,parent=None):
    super(MyMainWindow,self).init(parent)
    QtCore.QTimer.singleShot(1000,self.setupHsm)

    def setupHsm(self):
       self.state_machine = QtCore.QStateMachine()
       self.one_state = QtCore.QState()
       self.other_state = QtCore.QState()
       self.one_state.addTransition(self,
               "test_signal1()",self.other_state)
       self.one_state.addTransition(self,
               "test_signal2(int)",self.other_state)
       self.one_state.addTransition(self,
               "test_signal3(str)",self.other_state)
    

    if name == "main":
    app = QtGui.QApplication(sys.argv)
    myapp = MyMainWindow()
    myapp.show()
    sys.exit(app.exec_())
    @

    When I execute this I get:
    @
    QState::addTransition: no such signal MyMainWindow::test_signal3(str)
    @

    I added three different transitions. One without a parameter, one with an int- and one with a str-parameter. The third does not work. Having a str-parameter seems to cause trouble. Does anyone know why?

    Btw. the hack with the timer is just to exclude any mess that might be caused by doing these things from the init method (which should be no problem, but still...). Usually I would do this from init.

    Some tech info:

    PySide 1.1 (Tested 1.2 too, same effect)
    Python2.7
    Ubuntu precise

    Thanks for any help

    Soraltan



  • Hi,

    still got no solution for this and trying to work around this problems in all my HSM-related code. Quite annoying.

    Anyhow, I unearthed some further info on the topic. Unfortunatly this make the issue even more mysterious. I found out that adding a SIGNAL() around the string in line 21 of the previous posting makes the problem disappear. Well it makes the message disappear. I then constructed some code that would help testing whether or not the state switch really occurred:

    @
    from PySide import QtCore, QtGui
    import sys

    class MyMainWindow(QtGui.QMainWindow):
    test_signal1 = QtCore.Signal()
    test_signal2 = QtCore.Signal(int)
    test_signal3 = QtCore.Signal(str)
    def init(self,parent=None):
    super(MyMainWindow,self)
    .init(parent)
    QtCore.QTimer.singleShot(
    1000,self.setupHsm)
    QtCore.QTimer.singleShot(
    3000,self.sendSignal)
    QtCore.QTimer.singleShot(
    1500,self.printConf)
    QtCore.QTimer.singleShot(
    3500,self.printConf)

    def setupHsm(self):
         self.state_machine = QtCore
                 .QStateMachine()
         self.one_state = QtCore
                 .QState(self.state_machine)
         self.state_machine
                 .setInitialState(
                 self.one_state)    
         self.other_state = QtCore
                 .QState(self.state_machine)
         self.one_state.addTransition(self,
               "test_signal1()"
                 ,self.other_state)
         self.one_state.addTransition(self,
               "test_signal2(int)"
                 ,self.other_state)
         self.one_state.addTransition(self,
               QtCore.SIGNAL("test_signal3(str)")
                ,self.other_state)
         self.state_machine.start()
         print self.state_machine.configuration()
    
    def printConf(self):
         print self.state_machine.configuration()
    
    def sendSignal(self):
        self.test_signal3.emit("bla")
        print self.state_machine.configuration()
    

    if name == "main":
    app = QtGui.QApplication(sys.argv)
    myapp = MyMainWindow()
    myapp.show()
    sys.exit(app.exec_())
    @
    What I get is this:
    @
    set([])
    set([<PySide.QtCore.QState object at 0xa15454c>])
    set([<PySide.QtCore.QState object at 0xa15454c>])
    set([<PySide.QtCore.QState object at 0xa15454c>])
    @

    First thing I noted was the empty configuration directly after the start of the HSM (printed in line 39). That's why I introduced a method that prints the configuration and is called half a second alter. This gives a reasonable output. Apparently I need to return to the EventQueue after starting the HSM.

    However after emitting test_signal3 the configuration remains unchanged. Even after returning to the EventQueue (again using a QTimer::singleShot). On the other hand when emitting test_signal2 (istead of 3) in line 45, the change in the state can be observed.

    @
    set([<PySide.QtCore.QState object at 0x8a1154c>])
    set([<PySide.QtCore.QState object at 0x8a1156c>])
    set([<PySide.QtCore.QState object at 0x8a1156c>])
    @

    Can anyone help. Or at least test whether the above code yields similar results?

    Thanks


Log in to reply
 

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