-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
35 lines (28 loc) · 958 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QMqttClient>
#include <QDebug>
#include <QTimer>
#include "component/cr_protocol.h"
#include "component/robot_message.h"
#include "component/mqttclient.h"
#include "QQmlContext"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
crProtocol protocol; // 创建crProtocol对象
robotMessage robotMsg; // 创建robotMessage对象
mqttClient mqttHandler;
engine.rootContext()->setContextProperty("mqttClient",&mqttHandler); // 让QML认识实例化的mqttHandler
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreationFailed,
&app,
[]() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.loadFromModule("RobotViewerCpp", "Main");
mqttHandler.init(protocol, robotMsg);
mqttHandler.setClientID("Robot_Tool");
return app.exec();
}