示例#1
0
文件: main.cpp 项目: Slesa/Trinity
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    TrafficLight widget;
    widget.resize(110, 300);
    widget.show();

    return a.exec();
}
示例#2
0
/**
 * @brief Create a GUI driven by a state machine, realtime-debug this state machine in another window
 */
int main(int argc, char** argv)
{
    QApplication app(argc, argv);

    //! [Target setup]
    TrafficLight trafficLight;
    trafficLight.resize(110, 300);
    trafficLight.show();

    // set up the debug interface on the local registry and connect to it
    // this is simpler than writing another class that handles in-process debuggging
    // just pay the cost for the in-process communication, it's not that much anyway
    QRemoteObjectRegistryHost registryHostNode(QUrl(QStringLiteral("local:registry")));
    QRemoteObjectHost hostNode(QUrl(QStringLiteral("local:replica")), QUrl(QStringLiteral("local:registry")));
    QsmDebugInterfaceSource interfaceSource;
    interfaceSource.setQStateMachine(trafficLight.machine());
    hostNode.enableRemoting(interfaceSource.remoteObjectSource());
    //! [Target setup]

    //! [Client setup for viewing the state machine]
    StateMachineView view;
    view.resize(800, 600);
    view.show();

    QRemoteObjectNode clientNode(QUrl(QStringLiteral("local:registry")));
    auto interfaceReplica = clientNode.acquire<DebugInterfaceReplica>();
    interfaceReplica->waitForSource();

    DebugInterfaceClient client;
    client.setDebugInterface(interfaceReplica);
    QObject::connect(&client, &DebugInterfaceClient::repopulateView,
                     [&]() {
            qDebug() << "Updating state machine in view";
            view.scene()->setRootState(client.machine());
            view.scene()->layout();
        }
    );
    //! [Client setup for viewing the state machine]

    app.exec();
}