[Qt-interest] QStatemachine: Enter state and assignProperty() issue

Sean Harmer sean.harmer at maps-technology.com
Fri Mar 18 15:50:32 CET 2011


On Friday 18 March 2011 19:38:20 Mandeep Sandhu wrote:
> Hi All,
> 
> I'm using QSM to control some GUI widgets in an application. I use the
> property assignment feature of QSM to make a widget "visible" (using
> QWidgets visible property), when its in the state that the widget
> represents and, "invisible" when its not.
> 
> I also use the QState::onEnty()/onExit() callbacks to do some actions
> specific to a state.
> 
> The widgets attached to a state expect to be visible when the SM
> enters the state. But I found that the property assignment happens
> once I return from the onEntry() callback. So any widget that expects
> itself to be visible, will not be when we enter the state.
> 
> How should such a situation be handled? Should I call the widgets
> enter/exit state callbacks using a Timer and not directly from
> QState::onEntry()/onExit() functions? Whats a reliable place to assume
> that all property assignments have taken place?

A few options:

* Explicitly call show()/hide() in your onEntry()/onExit() functions for that 
state.

* Provide a pair of specialised signals on that state sub-class, emit these 
from the onEntry()/onExit() functions and use these signals rather than the 
property assignment method.

* Use the QAbstractTransition::triggered() signals to toggle the widget 
visibility instead. The transition will happen before the state's onEntry(). 
Not sure about the onExit() though so you;d have to check.

HTH,

Sean




More information about the Qt-interest-old mailing list