SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
Integrated Computer Solutions Inc. www.ics.com
An Introduction to the Qt State
Machine Framework using Qt 6
December 16, 2021
Christopher Probst, ICS
1
Integrated Computer Solutions Inc. www.ics.com
About ICS
Delivering Smart Devices for a Connected World
● Founded in 1987
● Largest source of independent Qt expertise in North America
● Trusted Qt Service Partner since 2002
● Exclusive Open Enrollment Training Partner in North America
● Provides integrated custom software development and user experience (UX) design
● Embedded, touchscreen, mobile and desktop applications
● HQ in Waltham, MA with offices in California, Canada, Europe
Boston UX
● Part of the ICS family, focusing on UX design
● Designs intuitive touchscreen interfaces for high-impact embedded
and connected medical, industrial and consumer devices
2
Integrated Computer Solutions Inc. www.ics.com
● A C++, (and also QML) API that allows to create and execute state graphs
● Not to be confused with the state and transitions from Item in QML
● Based on Harel’s statecharts
● Allows for hierarchical statecharts with superstates
● State Machine is signal and event driven
● https://doc-snapshots.qt.io/qt6-dev/qtstatemachine-index.html
What is the Qt State Machine Framework
3
Integrated Computer Solutions Inc. www.ics.com
C++ Type Description
QStateMachine Provides a hierarchical finite state machine
QState Provides a state for the state machine
QHistoryState Provides a means of returning to a previously active sub-state
QFinalState Provides a final state
QSignalTransition Provides a transition based on a Qt signal
QEventTransition Provides an a transition based on a QEvent
Note: To access the API it is necessary to link against the Qt module StateMachine:
C++ Types Available
find_package(Qt6 COMPONENTS StateMachine REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::StateMachine)
CMakeLists.txt
4
Integrated Computer Solutions Inc. www.ics.com
An Example
5
Integrated Computer Solutions Inc. www.ics.com
Business Logic/UI Paradigm
-
BusinessLogic
C++
UI in QML
● C++ code “knows” nothing of the implementation details in QML
6
Integrated Computer Solutions Inc. www.ics.com
Using C++ and QML
7
7
Integrated Computer Solutions Inc. www.ics.com
Creating State Machine
8
Just create an instance of a QStateMachine in the business logic...
class ScreenSelector : public QObject
{
Q_OBJECT
Q_PROPERTY(QUrl currentScreen READ currentScreen WRITE setCurrentScreen NOTIFY currentScreenChanged)
public:
explicit ScreenSelector(QObject *parent = nullptr);
const QUrl &currentScreen() const;
void setCurrentScreen(const QUrl &newCurrentScreen);
signals:
void currentScreenChanged();
private:
QUrl m_currentScreen;
QStateMachine m_statemachine; //instantiating a QStateMachine object
};
Integrated Computer Solutions Inc. www.ics.com
Creating States
QState *loggedInstate = new QState();
loggedInstate->setObjectName("LoggedIn");
loggedInstate->assignProperty(this, "currentScreen",
QUrl("CoolApplication.qml"));
QState *loggedOutState = new QState();
loggedOutState->setObjectName("LoggedOut");
loggedOutState->assignProperty(this, "currentScreen",
QUrl("LoginScreen.qml"));
QState *screnSaverMode = new QState();
screnSaverMode->setObjectName("ScrenSaverMode");
screnSaverMode->assignProperty(this, "currentScreen",
QUrl("ScreenSaver.qml"));
9
● Just create an instance of a QState
in the business logic
● QState represents a set of properties
and values
● The entry into a state triggers the
value setting of properties as
specified with the method
QState::assignProperty(QObject *,
char *, const QVariant &)
Integrated Computer Solutions Inc. www.ics.com
Creating a Superstate
QState *working = new QState(); //This is a super State
working->setObjectName("working");
QState *loggedInstate = new QState(working);
loggedInstate->setObjectName("loggedIn");
loggedInstate->assignProperty(this, "currentScreen",
QUrl("CoolApplication.qml"));
QState *loggedOutState = new QState(working);
loggedOutState->setObjectName("loggedOut");
loggedOutState->assignProperty(this, "currentScreen",
QUrl("LoginScreen.qml"));
QHistoryState *workingh = new QHistoryState(working);
working->setInitialState(loggedInstate);
10
Just create an instance of a QState and use
the parent/child relationship to specify the
state hierarchy
Set an initial state of the superstate with
QState::setInitialState(QAbstractState)
Take advantage of QHistoryState to reference
its last active sub-state
Integrated Computer Solutions Inc. www.ics.com
Adding States to the State Machine
QState *working = new QState(); //This is a super State
...
QState *loggedInstate = new QState(working);
...
QState *loggedOutState = new QState(working);
...
QHistoryState *workingh = new QHistoryState(working);
QState *screnSaverMode = new QState();
...
//Adding States to State Machine
m_statemachine.addState( working );
m_statemachine.addState( screnSaverMode );
m_statemachine.setInitialState( loggedInstate) ;
m_statemachine.start()
● Use void
QStateMachine::addState(QAbstract
State *state)
● Or make the states children of the
state machine
● Set the initial using void
QState::setInitialState(QAbstract
State *state)
● Don’t forget to start the machine
using void QStateMachine::start()
11
Integrated Computer Solutions Inc. www.ics.com
But What About the Transitions?
12
QState *loggedInstate = new QState(working);
...
QState *loggedOutState = new QState(working);
...
loggedOutState->addTransition(&m_communicationLayer,
&CommunicationLayer::loggedIn,
loggedInstate);
loggedInstate->addTransition(&m_communicationLayer,
&CommunicationLayer::loggedOut,
loggedOutState);
● Use QState::addTransition
● Can be used directly with instance of a QSignalTransition or QEventTransition
Integrated Computer Solutions Inc. www.ics.com
And What about the History and Super State?
13
QState *working = new QState(); //This is a super State
QHistoryState *workingh = new QHistoryState(working);
…
QState *screenSaverMode = new QState();
screenSaverMode->setObjectName("screnSaverMode");
screenSaverMode->assignProperty(this, "currentScreen",
QUrl("Screensaver.qml"));
working->addTransition(this, &ScreenSelector::inactiveForTooLong,
screenSaverMode);
screenSaverMode->addTransition(this, &ScreenSelector::wokenUp,
workingh);
● Still Use QState::addTransition
● The History state refers to the last active sub-state
Integrated Computer Solutions Inc. www.ics.com
Retrieving States from the State Machine
14
//Retrieving Logged Out State
QState* aState = m_statemachine.findChild<QState*>("loggedOut");
//Retrieving all States
QList<QState*> states =
m_statemachine.findChildren<QState*>( QRegularExpression(".*") );
//Retrieving Direct States
QList<QObject*> states = m_statemachine.children();
//Display current states of state machine upon entry of specialState
connect(*specialState, &QState::entered,
[this](){
qDebug() << m_statemachine.configuration();
}
);
● The QObject parent/child
relationship applies
● QStates are children of
QStateMachine
● The QObject findChild() and
findChildren() methods assist in
retrieving states
● QStateMachine::configuration() lists
the current states of a state
machine
Integrated Computer Solutions Inc. www.ics.com
Conditional Transitions
15
class ConditionalTransition : public QSignalTransition {
Q_OBJECT
Q_PROPERTY(bool canTrigger READ canTrigger WRITE setCanTrigger)
public:
ConditionalTransition(QState * sourceState = 0): QSignalTransition(sourceState)
{
m_canTrigger = false;
}
void setCanTrigger(bool v) { m_canTrigger = v; }
bool canTrigger() const { return m_canTrigger; }
protected:
bool eventTest(QEvent *e) {
if(!QSignalTransition::eventTest(e))
return false;
return canTrigger(); }
private:
bool m_canTrigger;
}
● Somewhat tricky
● Requires the re-implementation of
a transition class
● And the re-implementation of
bool eventTest(QEvent *event)
● Return true if the condition is met
Integrated Computer Solutions Inc. www.ics.com
Advantages of Using the State Machine Framework
16
● Allows for Graphical State Machine Designer Tooling.
Examples:
● Qt SCXML https://doc.qt.io/qt-5/qtscxml-overview.html,
● KDAB State machine Editor
https://github.com/KDAB/KDStateMachineEditor
● Would allow for analysis of the overall logic
● Allows for easy and precise documentation of requirements
Integrated Computer Solutions Inc. www.ics.com
Thank you!
17
Any questions?

Contenu connexe

Tendances

Qt Internationalization
Qt InternationalizationQt Internationalization
Qt InternationalizationICS
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? ICS
 
Best Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVBest Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVICS
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentICS
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIICS
 
Qt State Machine Framework
Qt State Machine FrameworkQt State Machine Framework
Qt State Machine Frameworkaccount inactive
 
Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3ICS
 
Qt for beginners part 1 overview and key concepts
Qt for beginners part 1   overview and key conceptsQt for beginners part 1   overview and key concepts
Qt for beginners part 1 overview and key conceptsICS
 
Introduction to QML
Introduction to QMLIntroduction to QML
Introduction to QMLAlan Uthoff
 
Introduction to the Qt Quick Scene Graph
Introduction to the Qt Quick Scene GraphIntroduction to the Qt Quick Scene Graph
Introduction to the Qt Quick Scene GraphICS
 
Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4ICS
 
Qt Framework Events Signals Threads
Qt Framework Events Signals ThreadsQt Framework Events Signals Threads
Qt Framework Events Signals ThreadsNeera Mital
 
Practical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme ChangePractical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme ChangeBurkhard Stubert
 

Tendances (20)

Qt Internationalization
Qt InternationalizationQt Internationalization
Qt Internationalization
 
QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong? QThreads: Are You Using Them Wrong?
QThreads: Are You Using Them Wrong?
 
Best Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IVBest Practices in Qt Quick/QML - Part IV
Best Practices in Qt Quick/QML - Part IV
 
QVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI developmentQVariant, QObject — Qt's not just for GUI development
QVariant, QObject — Qt's not just for GUI development
 
UI Programming with Qt-Quick and QML
UI Programming with Qt-Quick and QMLUI Programming with Qt-Quick and QML
UI Programming with Qt-Quick and QML
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part III
 
Qt State Machine Framework
Qt State Machine FrameworkQt State Machine Framework
Qt State Machine Framework
 
Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2Qt Application Programming with C++ - Part 2
Qt Application Programming with C++ - Part 2
 
Introduction to Qt programming
Introduction to Qt programmingIntroduction to Qt programming
Introduction to Qt programming
 
02 - Basics of Qt
02 - Basics of Qt02 - Basics of Qt
02 - Basics of Qt
 
Qt Workshop
Qt WorkshopQt Workshop
Qt Workshop
 
Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3Best Practices in Qt Quick/QML - Part 3
Best Practices in Qt Quick/QML - Part 3
 
Qt for beginners part 1 overview and key concepts
Qt for beginners part 1   overview and key conceptsQt for beginners part 1   overview and key concepts
Qt for beginners part 1 overview and key concepts
 
Introduction to QML
Introduction to QMLIntroduction to QML
Introduction to QML
 
Introduction to the Qt Quick Scene Graph
Introduction to the Qt Quick Scene GraphIntroduction to the Qt Quick Scene Graph
Introduction to the Qt Quick Scene Graph
 
Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4Best Practices in Qt Quick/QML - Part 4
Best Practices in Qt Quick/QML - Part 4
 
Qt Framework Events Signals Threads
Qt Framework Events Signals ThreadsQt Framework Events Signals Threads
Qt Framework Events Signals Threads
 
Qt 5 - C++ and Widgets
Qt 5 - C++ and WidgetsQt 5 - C++ and Widgets
Qt 5 - C++ and Widgets
 
Practical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme ChangePractical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme Change
 
Qt Qml
Qt QmlQt Qml
Qt Qml
 

Similaire à Introduction to the Qt State Machine Framework using Qt 6

Integrazione QML / C++
Integrazione QML / C++Integrazione QML / C++
Integrazione QML / C++Paolo Sereno
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarICS
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarJanel Heilbrunn
 
Cassandra Day Denver 2014: Building Java Applications with Apache Cassandra
Cassandra Day Denver 2014: Building Java Applications with Apache CassandraCassandra Day Denver 2014: Building Java Applications with Apache Cassandra
Cassandra Day Denver 2014: Building Java Applications with Apache CassandraDataStax Academy
 
Qt & Webkit
Qt & WebkitQt & Webkit
Qt & WebkitQT-day
 
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2NokiaAppForum
 
Recoil at Codete Webinars #3
Recoil at Codete Webinars #3Recoil at Codete Webinars #3
Recoil at Codete Webinars #3Mateusz Bryła
 
Qt for beginners part 4 doing more
Qt for beginners part 4   doing moreQt for beginners part 4   doing more
Qt for beginners part 4 doing moreICS
 
Hybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKitHybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKitAriya Hidayat
 
Hybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitHybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitAriya Hidayat
 
Hybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitHybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitAriya Hidayat
 
How to write automated tests and don’t lose your mind by Dorian Sarnowski Scalac
How to write automated tests and don’t lose your mind by Dorian Sarnowski ScalacHow to write automated tests and don’t lose your mind by Dorian Sarnowski Scalac
How to write automated tests and don’t lose your mind by Dorian Sarnowski ScalacScalac
 
embedding web browser in your app
embedding web browser in your appembedding web browser in your app
embedding web browser in your appSamsung
 

Similaire à Introduction to the Qt State Machine Framework using Qt 6 (20)

Integrazione QML / C++
Integrazione QML / C++Integrazione QML / C++
Integrazione QML / C++
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - Webinar
 
Porting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - WebinarPorting Motif Applications to Qt - Webinar
Porting Motif Applications to Qt - Webinar
 
Cassandra Day Denver 2014: Building Java Applications with Apache Cassandra
Cassandra Day Denver 2014: Building Java Applications with Apache CassandraCassandra Day Denver 2014: Building Java Applications with Apache Cassandra
Cassandra Day Denver 2014: Building Java Applications with Apache Cassandra
 
Qt & Webkit
Qt & WebkitQt & Webkit
Qt & Webkit
 
Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2Petri Niemi Qt Advanced Part 2
Petri Niemi Qt Advanced Part 2
 
Recoil at Codete Webinars #3
Recoil at Codete Webinars #3Recoil at Codete Webinars #3
Recoil at Codete Webinars #3
 
State Machine Framework
State Machine FrameworkState Machine Framework
State Machine Framework
 
Hello, QML
Hello, QMLHello, QML
Hello, QML
 
Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
 
Qt for beginners part 4 doing more
Qt for beginners part 4   doing moreQt for beginners part 4   doing more
Qt for beginners part 4 doing more
 
Treinamento Qt básico - aula II
Treinamento Qt básico - aula IITreinamento Qt básico - aula II
Treinamento Qt básico - aula II
 
New Features in QP5
New Features in QP5New Features in QP5
New Features in QP5
 
Hybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKitHybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKit
 
New Design of OneRing
New Design of OneRingNew Design of OneRing
New Design of OneRing
 
Hybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitHybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKit
 
Hybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitHybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKit
 
The Mobility Project
The Mobility ProjectThe Mobility Project
The Mobility Project
 
How to write automated tests and don’t lose your mind by Dorian Sarnowski Scalac
How to write automated tests and don’t lose your mind by Dorian Sarnowski ScalacHow to write automated tests and don’t lose your mind by Dorian Sarnowski Scalac
How to write automated tests and don’t lose your mind by Dorian Sarnowski Scalac
 
embedding web browser in your app
embedding web browser in your appembedding web browser in your app
embedding web browser in your app
 

Plus de ICS

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfICS
 
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...ICS
 
Overcoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarOvercoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarICS
 
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdfEnhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdfICS
 
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdfDesigning and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdfICS
 
Quality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdfQuality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdfICS
 
Creating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdfCreating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdfICS
 
Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up ICS
 
Cybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfCybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfICS
 
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesMDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesICS
 
How to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionHow to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionICS
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsICS
 
IoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureIoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureICS
 
Basic Cmake for Qt Users
Basic Cmake for Qt UsersBasic Cmake for Qt Users
Basic Cmake for Qt UsersICS
 
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...ICS
 
Qt Installer Framework
Qt Installer FrameworkQt Installer Framework
Qt Installer FrameworkICS
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsICS
 
Overcome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyOvercome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyICS
 
User Experience Design for IoT
User Experience Design for IoTUser Experience Design for IoT
User Experience Design for IoTICS
 

Plus de ICS (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdfPractical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdf
 
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
Accelerating Development of a Safety-Critical Cobot Welding System with Qt/QM...
 
Overcoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues WebinarOvercoming CMake Configuration Issues Webinar
Overcoming CMake Configuration Issues Webinar
 
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdfEnhancing Quality and Test in Medical Device Design - Part 2.pdf
Enhancing Quality and Test in Medical Device Design - Part 2.pdf
 
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdfDesigning and Managing IoT Devices for Rapid Deployment - Webinar.pdf
Designing and Managing IoT Devices for Rapid Deployment - Webinar.pdf
 
Quality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdfQuality and Test in Medical Device Design - Part 1.pdf
Quality and Test in Medical Device Design - Part 1.pdf
 
Creating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdfCreating Digital Twins Using Rapid Development Techniques.pdf
Creating Digital Twins Using Rapid Development Techniques.pdf
 
Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up
 
Cybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfCybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdf
 
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesMDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
 
How to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionHow to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management Solution
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
 
IoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureIoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with Azure
 
Basic Cmake for Qt Users
Basic Cmake for Qt UsersBasic Cmake for Qt Users
Basic Cmake for Qt Users
 
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
 
Qt Installer Framework
Qt Installer FrameworkQt Installer Framework
Qt Installer Framework
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
 
Overcome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyOvercome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case Study
 
User Experience Design for IoT
User Experience Design for IoTUser Experience Design for IoT
User Experience Design for IoT
 

Dernier

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 

Dernier (20)

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 

Introduction to the Qt State Machine Framework using Qt 6

  • 1. Integrated Computer Solutions Inc. www.ics.com An Introduction to the Qt State Machine Framework using Qt 6 December 16, 2021 Christopher Probst, ICS 1
  • 2. Integrated Computer Solutions Inc. www.ics.com About ICS Delivering Smart Devices for a Connected World ● Founded in 1987 ● Largest source of independent Qt expertise in North America ● Trusted Qt Service Partner since 2002 ● Exclusive Open Enrollment Training Partner in North America ● Provides integrated custom software development and user experience (UX) design ● Embedded, touchscreen, mobile and desktop applications ● HQ in Waltham, MA with offices in California, Canada, Europe Boston UX ● Part of the ICS family, focusing on UX design ● Designs intuitive touchscreen interfaces for high-impact embedded and connected medical, industrial and consumer devices 2
  • 3. Integrated Computer Solutions Inc. www.ics.com ● A C++, (and also QML) API that allows to create and execute state graphs ● Not to be confused with the state and transitions from Item in QML ● Based on Harel’s statecharts ● Allows for hierarchical statecharts with superstates ● State Machine is signal and event driven ● https://doc-snapshots.qt.io/qt6-dev/qtstatemachine-index.html What is the Qt State Machine Framework 3
  • 4. Integrated Computer Solutions Inc. www.ics.com C++ Type Description QStateMachine Provides a hierarchical finite state machine QState Provides a state for the state machine QHistoryState Provides a means of returning to a previously active sub-state QFinalState Provides a final state QSignalTransition Provides a transition based on a Qt signal QEventTransition Provides an a transition based on a QEvent Note: To access the API it is necessary to link against the Qt module StateMachine: C++ Types Available find_package(Qt6 COMPONENTS StateMachine REQUIRED) target_link_libraries(mytarget PRIVATE Qt6::StateMachine) CMakeLists.txt 4
  • 5. Integrated Computer Solutions Inc. www.ics.com An Example 5
  • 6. Integrated Computer Solutions Inc. www.ics.com Business Logic/UI Paradigm - BusinessLogic C++ UI in QML ● C++ code “knows” nothing of the implementation details in QML 6
  • 7. Integrated Computer Solutions Inc. www.ics.com Using C++ and QML 7 7
  • 8. Integrated Computer Solutions Inc. www.ics.com Creating State Machine 8 Just create an instance of a QStateMachine in the business logic... class ScreenSelector : public QObject { Q_OBJECT Q_PROPERTY(QUrl currentScreen READ currentScreen WRITE setCurrentScreen NOTIFY currentScreenChanged) public: explicit ScreenSelector(QObject *parent = nullptr); const QUrl &currentScreen() const; void setCurrentScreen(const QUrl &newCurrentScreen); signals: void currentScreenChanged(); private: QUrl m_currentScreen; QStateMachine m_statemachine; //instantiating a QStateMachine object };
  • 9. Integrated Computer Solutions Inc. www.ics.com Creating States QState *loggedInstate = new QState(); loggedInstate->setObjectName("LoggedIn"); loggedInstate->assignProperty(this, "currentScreen", QUrl("CoolApplication.qml")); QState *loggedOutState = new QState(); loggedOutState->setObjectName("LoggedOut"); loggedOutState->assignProperty(this, "currentScreen", QUrl("LoginScreen.qml")); QState *screnSaverMode = new QState(); screnSaverMode->setObjectName("ScrenSaverMode"); screnSaverMode->assignProperty(this, "currentScreen", QUrl("ScreenSaver.qml")); 9 ● Just create an instance of a QState in the business logic ● QState represents a set of properties and values ● The entry into a state triggers the value setting of properties as specified with the method QState::assignProperty(QObject *, char *, const QVariant &)
  • 10. Integrated Computer Solutions Inc. www.ics.com Creating a Superstate QState *working = new QState(); //This is a super State working->setObjectName("working"); QState *loggedInstate = new QState(working); loggedInstate->setObjectName("loggedIn"); loggedInstate->assignProperty(this, "currentScreen", QUrl("CoolApplication.qml")); QState *loggedOutState = new QState(working); loggedOutState->setObjectName("loggedOut"); loggedOutState->assignProperty(this, "currentScreen", QUrl("LoginScreen.qml")); QHistoryState *workingh = new QHistoryState(working); working->setInitialState(loggedInstate); 10 Just create an instance of a QState and use the parent/child relationship to specify the state hierarchy Set an initial state of the superstate with QState::setInitialState(QAbstractState) Take advantage of QHistoryState to reference its last active sub-state
  • 11. Integrated Computer Solutions Inc. www.ics.com Adding States to the State Machine QState *working = new QState(); //This is a super State ... QState *loggedInstate = new QState(working); ... QState *loggedOutState = new QState(working); ... QHistoryState *workingh = new QHistoryState(working); QState *screnSaverMode = new QState(); ... //Adding States to State Machine m_statemachine.addState( working ); m_statemachine.addState( screnSaverMode ); m_statemachine.setInitialState( loggedInstate) ; m_statemachine.start() ● Use void QStateMachine::addState(QAbstract State *state) ● Or make the states children of the state machine ● Set the initial using void QState::setInitialState(QAbstract State *state) ● Don’t forget to start the machine using void QStateMachine::start() 11
  • 12. Integrated Computer Solutions Inc. www.ics.com But What About the Transitions? 12 QState *loggedInstate = new QState(working); ... QState *loggedOutState = new QState(working); ... loggedOutState->addTransition(&m_communicationLayer, &CommunicationLayer::loggedIn, loggedInstate); loggedInstate->addTransition(&m_communicationLayer, &CommunicationLayer::loggedOut, loggedOutState); ● Use QState::addTransition ● Can be used directly with instance of a QSignalTransition or QEventTransition
  • 13. Integrated Computer Solutions Inc. www.ics.com And What about the History and Super State? 13 QState *working = new QState(); //This is a super State QHistoryState *workingh = new QHistoryState(working); … QState *screenSaverMode = new QState(); screenSaverMode->setObjectName("screnSaverMode"); screenSaverMode->assignProperty(this, "currentScreen", QUrl("Screensaver.qml")); working->addTransition(this, &ScreenSelector::inactiveForTooLong, screenSaverMode); screenSaverMode->addTransition(this, &ScreenSelector::wokenUp, workingh); ● Still Use QState::addTransition ● The History state refers to the last active sub-state
  • 14. Integrated Computer Solutions Inc. www.ics.com Retrieving States from the State Machine 14 //Retrieving Logged Out State QState* aState = m_statemachine.findChild<QState*>("loggedOut"); //Retrieving all States QList<QState*> states = m_statemachine.findChildren<QState*>( QRegularExpression(".*") ); //Retrieving Direct States QList<QObject*> states = m_statemachine.children(); //Display current states of state machine upon entry of specialState connect(*specialState, &QState::entered, [this](){ qDebug() << m_statemachine.configuration(); } ); ● The QObject parent/child relationship applies ● QStates are children of QStateMachine ● The QObject findChild() and findChildren() methods assist in retrieving states ● QStateMachine::configuration() lists the current states of a state machine
  • 15. Integrated Computer Solutions Inc. www.ics.com Conditional Transitions 15 class ConditionalTransition : public QSignalTransition { Q_OBJECT Q_PROPERTY(bool canTrigger READ canTrigger WRITE setCanTrigger) public: ConditionalTransition(QState * sourceState = 0): QSignalTransition(sourceState) { m_canTrigger = false; } void setCanTrigger(bool v) { m_canTrigger = v; } bool canTrigger() const { return m_canTrigger; } protected: bool eventTest(QEvent *e) { if(!QSignalTransition::eventTest(e)) return false; return canTrigger(); } private: bool m_canTrigger; } ● Somewhat tricky ● Requires the re-implementation of a transition class ● And the re-implementation of bool eventTest(QEvent *event) ● Return true if the condition is met
  • 16. Integrated Computer Solutions Inc. www.ics.com Advantages of Using the State Machine Framework 16 ● Allows for Graphical State Machine Designer Tooling. Examples: ● Qt SCXML https://doc.qt.io/qt-5/qtscxml-overview.html, ● KDAB State machine Editor https://github.com/KDAB/KDStateMachineEditor ● Would allow for analysis of the overall logic ● Allows for easy and precise documentation of requirements
  • 17. Integrated Computer Solutions Inc. www.ics.com Thank you! 17 Any questions?