Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在Qt-SCXML状态图中使用条件转换_C++_Qt_State Machine_Qtwidgets_Scxml - Fatal编程技术网

C++ 如何在Qt-SCXML状态图中使用条件转换

C++ 如何在Qt-SCXML状态图中使用条件转换,c++,qt,state-machine,qtwidgets,scxml,C++,Qt,State Machine,Qtwidgets,Scxml,我目前正在尝试理解Qts scxml状态图,以及如何在我的应用程序中正确地集成它们。我偶然发现的一个问题是条件转换。为了解释我在这里如何使用条件以及出现了什么问题,我举了一个最低可行的例子: 初始状态s_initial有两种状态转换为s_false和s_true。两个转换都由单击的相同事件触发。根据变量test\u var,任何时候都只能进行一次转换。当单击另一个t\u按钮时事件发生,状态机返回到s\u initial 为了测试状态机,我创建了一个简单的Qt Widgets应用程序,其中一个按

我目前正在尝试理解Qts scxml状态图,以及如何在我的应用程序中正确地集成它们。我偶然发现的一个问题是条件转换。为了解释我在这里如何使用条件以及出现了什么问题,我举了一个最低可行的例子:

初始状态
s_initial
有两种状态转换为
s_false
s_true
。两个转换都由单击的相同事件触发。根据变量
test\u var
,任何时候都只能进行一次转换。当单击另一个
t\u按钮时
事件发生,状态机返回到
s\u initial

为了测试状态机,我创建了一个简单的Qt Widgets应用程序,其中一个按钮用于触发点击的
t\u按钮,另一个复选框用于更改变量
test\u var

(mainwindow.cpp)

test\u var
的值是多少并不重要。状态机总是第一次转换到
s_false
,不检查我添加的条件。据我所知,我在图表中使用了有效的ecmascript表达式,scxml应该能够根据其特性选择正确的转换。我做错了什么

  • 您应该使用setScxmlProperty而不是setProperty

    chart.dataModel()->setScxmlProperty(“test_var”,选中“”)

  • 您可以简单地使用\u event.data传递复选框当前值

    chart.submitEvent(“点击按钮”,用户界面->复选框->选中()?1:0)

  • 
    

    另外,您可以使用下一个参考资料来更好地理解SCXML(我正在推广我自己的网站)
  • 您应该使用setScxmlProperty而不是setProperty

    chart.dataModel()->setScxmlProperty(“test_var”,选中“”)

  • 您可以简单地使用\u event.data传递复选框当前值

    chart.submitEvent(“点击按钮”,用户界面->复选框->选中()?1:0)

  • 
    

    另外,您可以使用下一个参考资料来更好地理解SCXML(我正在推广我自己的网站)

    当链接到您自己的网站或内容(或您所属的内容)时,您必须确保它不会被视为垃圾邮件。在Stack Exchange策略下,用户名中包含与URL相同的文本或在个人资料中提及该文本不被视为充分的披露。当链接到您自己的网站或内容(或您所关联的内容)时,您必须确保其不被视为垃圾邮件。在堆栈交换策略下,用户名中包含与URL相同的文本或在配置文件中提及该文本不被视为充分的披露。
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
        , chart(this)
    {
        ui->setupUi(this);
        connect(ui->checkBox, &QCheckBox::clicked, [this](bool checked){
            qDebug() << "> checkbox:" << checked;
            chart.dataModel()->setProperty("test_var", checked);
        });
        connect(ui->pushButton, &QPushButton::released, [this](){
            qDebug() << "> button";
            chart.submitEvent("t_button_clicked");
        });
        chart.start();
    }
    
    <?xml version="1.0" encoding="UTF-8"?>
    <scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" binding="early" xmlns:qt="http://www.qt.io/2015/02/scxml-ext" name="TestChart" qt:editorversion="4.14.1" datamodel="ecmascript" initial="s_initial">
        <qt:editorinfo initialGeometry="213.11;86.67;-20;-20;40;40"/>
        <state id="s_initial">
            <qt:editorinfo scenegeometry="213.11;233.50;153.11;183.50;120;100" geometry="213.11;233.50;-60;-50;120;100"/>
            <transition type="external" event="t_button_clicked" target="s_false" cond="!test_var">
                <qt:editorinfo endTargetFactors="11.79;50.87"/>
            </transition>
            <transition type="external" event="t_button_clicked" target="s_true" cond="test_var">
                <qt:editorinfo movePoint="37.73;-3.06" endTargetFactors="19.26;54.39"/>
            </transition>
            <onentry>
                <log expr="&quot;s_initial&quot;"/>
            </onentry>
        </state>
        <state id="s_false">
            <qt:editorinfo scenegeometry="529.21;233.50;469.21;183.50;120;100" geometry="529.21;233.50;-60;-50;120;100"/>
            <onentry>
                <log expr="&quot;s_false&quot;"/>
            </onentry>
            <transition type="external" event="t_button_clicked" target="s_initial">
                <qt:editorinfo movePoint="3.06;9.18" endTargetFactors="88.28;64.08" startTargetFactors="13.98;61.45"/>
            </transition>
        </state>
        <state id="s_true">
            <qt:editorinfo scenegeometry="529.21;419.09;469.21;369.09;120;100" geometry="529.21;419.09;-60;-50;120;100"/>
            <onentry>
                <log expr="&quot;s_true&quot;"/>
            </onentry>
            <transition type="external" event="t_button_clicked" target="s_initial">
                <qt:editorinfo movePoint="-37.73;6.12" endTargetFactors="68.74;85.18" startTargetFactors="14.04;72.02"/>
            </transition>
        </state>
        <datamodel>
            <data id="test_var" expr="false"/>
        </datamodel>
    </scxml>
    
    scxml.statemachine: "" : "s_initial"
    > checkbox: false
    > button
    scxml.statemachine: "" : "s_false"
    > button
    scxml.statemachine: "" : "s_initial"
    > checkbox: true
    > button
    scxml.statemachine: "" : "s_false"
    > button
    scxml.statemachine: "" : "s_initial"
    > checkbox: false
    > button
    scxml.statemachine: "" : "s_false"
    > button
    scxml.statemachine: "" : "s_initial"