Two-way Button ExampleFiles: The Two-way button example shows how to use The State Machine Framework to implement a simple state machine that toggles the current state when a button is clicked. int main(int argc, char **argv) { QApplication app(argc, argv); QPushButton button; QStateMachine machine; The application's main() function begins by constructing the application object, a button and a state machine. QState *off = new QState(); off->assignProperty(&button, "text", "Off"); off->setObjectName("off"); QState *on = new QState(); on->setObjectName("on"); on->assignProperty(&button, "text", "On"); The state machine has two states; on and off. When either state is entered, the text of the button will be set accordingly. off->addTransition(&button, SIGNAL(clicked()), on); on->addTransition(&button, SIGNAL(clicked()), off); 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. machine.addState(off); machine.addState(on); The states are added to the state machine; they become top-level (sibling) states. machine.setInitialState(off); machine.start(); The initial state is off; this is the state the state machine will immediately transition to once the state machine is started. button.resize(100, 50); button.show(); return app.exec(); } Finally, the button is resized and made visible, and the application event loop is entered. © 2008-2011 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. Privacy Policy Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia. Alternatively, this document may be used under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.7-snapshot | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter contacter par email ou par MP ! |
Responsables bénévoles de la rubrique Qt : Thibaut Cuvelier - Jonathan Courtois - Contacter par email
Copyright © 2000-2012 - www.developpez.com