×
Namespaces

Variants
Actions
Revision as of 06:48, 19 June 2012 by hamishwillee (Talk | contribs)

Archived:How to create a 2-state button using the Qt State Machine Framework

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.

This example shows how to use the Qt State Machine Framework to implement a simple state machine that toggles the current state when a button is clicked.

Article Metadata
Compatibility
Platform(s):
Symbian
Article
Created: chintandave_er (21 Nov 2010)
Last edited: hamishwillee (19 Jun 2012)

Implementation

  1. construct a button and a state machine
    QPushButton button;
    QStateMachine machine;
  2. Create two states: on and off. assign Property and ObjectName of the each state
     QState *off = new QState();
    off->assignProperty(&button, "text", "Off");
    off->setObjectName("off");
     
    QState *on = new QState();
    on->setObjectName("on");
    on->assignProperty(&button, "text", "On");
  3. When the state machine is in the off state and the button is clicked, it will transition to the on state; when the state machine is in the on state and the button is clicked, it will transition to the off state.
    off->addTransition(&button, SIGNAL(clicked()), on);
    on->addTransition(&button, SIGNAL(clicked()), off);
  4. add states to the state machine
    machine.addState(off);
    machine.addState(on);
  5. set the Initial State
    machine.setInitialState(off);
    machine.start();
  6. show the button
     button.resize(100, 50);
    button.show();

Related articles

67 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×