Calculadora SCXML
Um aplicativo que implementa o exemplo da Calculadora apresentado na Especificação SCXML.

A Calculadora utiliza o ` Qt SCXML ` para implementar o exemplo de Calculadora apresentado na Especificação SCXML.
A máquina de estados é especificada no arquivo statemachine.scxml e compilada na classe ` CalculatorStateMachine `. A interface do usuário é criada usando ` Qt Quick`.
Executando o exemplo
Você pode executar o exemplo a partir de:
- Qt Creator
Abra o modo “ Welcome ” e selecione o exemplo em Examples. Para mais informações, consulte Qt Creator: Tutorial: Compilar e executar.
- Qt Extension for Visual Studio Code
Execute o comando ` Qt: Open Qt examples ` a partir de ` Command Palette` e selecione o exemplo na lista. Para obter mais informações, consulte Qt Extension for Visual Studio Code: Tutorial: Compilar e executar.
Instanciando a máquina de estados
Tornamos a classe ` CalculatorStateMachine ` gerada disponível para o QML, declarando-a como um tipo QML no arquivo `calculator-qml.h`:
struct CalculatorStateMachineRegistration
{
Q_GADGET
QML_FOREIGN(CalculatorStateMachine)
QML_NAMED_ELEMENT(CalculatorStateMachine)
QML_ADDED_IN_VERSION(1, 0)
};Instanciamos uma CalculatorStateMachine e escutamos o evento ` updateDisplay `. Quando ele ocorre, alteramos o texto no visor da calculadora:
CalculatorStateMachine {
id: statemachine
running: true
EventConnection {
events: ["updateDisplay"]
onOccurred: (event)=> resultText.text = event.data.display
}
}Quando os usuários pressionam os botões da calculadora, os botões enviam eventos para a máquina de estados:
Button {
id: resultButton
x: 3 * width
y: parent.height / 5
textHeight: y - 2
fontHeight: 0.4
width: parent.width / 4
height: y * 4
color: pressed ? "#e0b91c" : "#face20"
text: "="
onClicked: statemachine.submitEvent("EQUALS")
}© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.