Qt QML State Machine Framework

Source: Internet
Author: User

Qt5.4introduced aQMLstate machine framework, withC + +similar to the state machine framework, you can create and execute a state diagram in your application. To this end,Qtqml.statemachinemodule provides a number of relevantQMLtype that is used to create an event-driven state machine, whichQMLThe types are listed below:

StateMachine -- state machine Butler, Execution algorithm is based on scxml ( state Chart XML Span style= "Font-family:dejavu Sans" > initialstate properties.

state--common types in the state machine, note theQtQuickin the module Statedifferent types, import the module firstQtQuickmodule, post-importQtqml.statemachinemodule.

finalstate-- As the name implies, using this state at the end of the state machine's work will trigger the state machine's finished () signal.

historystate-- is a pseudo state that records the last child state when exiting the parent state, at the beginning you can specify a default state.

signaltransition-- Toggles the state according to a specific signal.

timeouttransition-- Switch the status according to the timer.

The following is a comprehensive example:

qt5.4//Import the QtQuick module first, then import qtqml.statemachine module Imports QtQuick 2.4import qtquick.controls 1.2import qtqml.statemachine            1.0Item {width:400 height:200 Row {anchors.centerIn:parent spacing:10 Button { Id:startbutton text: "Start" onclicked: {//Start state machine if (!statemach            ine.running) {statemachine.running = True}}} Button { Id:button//state machine identification text:s11.active? "S11": S12.active? "S12": S13.active? "S13": "State"} button {Id:historybutton//history status record TEXT:STATEMACHINE.R Unning? S1.active?    "Interrupt": "Resume": "History"} Button {Id:quitbutton text: "Quit"} } statemachine {Id:statemachine initialstate:s1//Initial state//running:true//Running Property by button (St        Artbutton) settingsState {ID:S1 INITIALSTATE:S11//Initial status Signaltransition {targetstate:s                3//Toggle State signal:historyButton.clicked} Signaltransition according to signal { TARGETSTATE:S2//Toggle State signal:quitButton.clicked} Onentered:console according to signal. Log ("S1 entered") OnExited:console.log ("S1 exited") state {ID:S11 Sig               naltransition {targetstate:s12//toggle State signal:button.clicked based on signal            } onEntered:console.log ("S11 entered") OnExited:console.log ("S11 exited")} State {ID:S12 Signaltransition {//Toggle state targetstate According to signal: S13 signal:button.clicked} signaltransition {//override the signal of the parent state (qui        tbutton.clicked)           Signal:quitButton.clicked onTriggered:console.log ("Override-quitbutton clicked")             } onEntered:console.log ("S12 entered") OnExited:console.log ("S12 exited")} State {ID:S13 Signaltransition {//Toggle State TargetS based on signal                    Tate:s11 signal:button.clicked} timeouttransition {//switch state by timer Targetstate:s2 timeout:2000} onEntered:console.log ("                S13 entered ") OnExited:console.log (" S13 exited ")} historystate {//History state                Id:history}} state {ID:S3 signaltransition {//toggle State based on signal Targetstate:history signal:historyButton.clicked} onentered:console      . log ("S3 entered")      OnExited:console.log ("S3 exited")} finalstate {ID:S2} Onfinished:consol E.log ("state Finished")}}

Plus , state Span style= "Font-family:wenquanyi Micro Hei" >childmode property by default is a single-state mode, initially to set an initial state, we can also set the childmode for parallel mode, when entering the parent state, Will go into all the sub-states at the same time.

detailed information can be found below Qt Official documents:

Http://doc.qt.io/qt-5/qmlstatemachine.html


Qt QML State Machine Framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.