Calcolatrice SCXML
Un'applicazione che implementa l'esempio "Calcolatrice" presentato nella specifica SCXML.

Calculator utilizza Qt SCXML per implementare l’esempio "Calculator " presentato nella specifica SCXML.
La macchina a stati è specificata nel file statemachine.scxml e compilata nella classe CalculatorStateMachine. L’interfaccia utente viene creata utilizzando Qt Quick.
Esecuzione dell’esempio
È possibile eseguire l’esempio da:
- Qt Creator
Aprire la modalità Welcome e selezionare l’esempio da Examples. Per ulteriori informazioni, consultare Qt Creator: Tutorial: Compilazione ed esecuzione.
- Qt Extension for Visual Studio Code
Eseguire il comando Qt: Open Qt examples da Command Palette e selezionare l’esempio dall’elenco. Per ulteriori informazioni, consultare Qt Extension for Visual Studio Code: Tutorial: Compilazione ed esecuzione.
Istanziamento della macchina a stati
Rendiamo la classe CalculatorStateMachine generata disponibile per QML dichiarandola come tipo QML nel file calculator-qml.h:
struct CalculatorStateMachineRegistration
{
Q_GADGET
QML_FOREIGN(CalculatorStateMachine)
QML_NAMED_ELEMENT(CalculatorStateMachine)
QML_ADDED_IN_VERSION(1, 0)
};Istanziamo una CalculatorStateMachine e ascoltiamo l’evento updateDisplay. Quando si verifica, modifichiamo il testo sul display della calcolatrice:
CalculatorStateMachine {
id: statemachine
running: true
EventConnection {
events: ["updateDisplay"]
onOccurred: (event)=> resultText.text = event.data.display
}
}Quando gli utenti premono i tasti della calcolatrice, questi inviano degli eventi alla macchina a stati:
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.