c++ - QStateMachine with RestoreProperty is losing property on transition -
The QT document for state machines uses two principles: I The first properties allow one to provide QState, the other to trigger events in only one specific situation.
When I add both functions, restoring properties is no longer working. When a QSignalTransition
is removed, properties are set to their initial values (before the state machine is started), even if the current situation is not left.
I have a small example to reproduce it:
#include & lt; QApplication & gt; # Include & lt; QWidget & gt; # Include & lt; QPushButton & gt; # Include & lt; QVBoxLayout & gt; # Include & lt; QStateMachine & gt; # Include & lt; QSignalTransition & gt; Int main (int argc, char * argv []) {Q Application A (argc, argv); QWidget * w = new QWidget; QStateMachine * machine = new QStateMachine (w); QState * s1 = new QState; QState * s2 = new QState; QVBoxLayout * layout = new QVBoxLayout (w); QPushButton * btnState = new QPushButton ("Not set"); QPushButton * btnTrigger = New QPushButton ("Trigger"); Layout & gt; AddWidget (btnState); Layout & gt; AddWidget (btnTrigger); Machine & gt; SetGlobalRestorePolicy (QStateMachine :: RestoreProperties); S1-> AssignProperty (btnState, "text", "S1"); S2-> AssignProperty (btnState, "text", "S2"); S1-> AddTransition (btnState, signal (clicked)), s2); S2-> AddTransition (btnState, Signal (Clicked), S1); QSignalTransition * sig = new QSignalTransition (btnTrigger, signal (clicked ()); S1-> AddTransition (SIG); Machine & gt; AddState (S1); Machine & gt; AddState (s2); Machine & gt; SetInitialState (S1); Machine - & gt; Start (); W & gt; Show (); Back a.exec (); }
There are two buttons: state buttons toggle between S1 and S2, the trigger button runs a precise transition when S1 is activated. When triggered S1 is activated, the button text will be set back to "not set"
. If I understand setGlobalRestorePolicy ()
correctly, the property should be "S1"
, because this state is the value of S1, and the state was not left and Still active
Is there something wrong with me or misunderstood, or have I done something wrong?
I'm using QT 4.8.4 on windows, if it makes a difference. / P>
Comments
Post a Comment