1.QGC中实现c++端与qml交互
在QGCApplication.cc中通过qmlRegisterType注册
qmlRegisterType<ExternalWindow> ("QGroundControl.Controls", 1, 0, "ExternalWindow");
2.在c++端声明函数时加上Q_INVOKABLE修饰
qml端可以直接调用该函数
public:
explicit ExternalWindow(QObject *parent = nullptr);
Q_INVOKABLE void startExternalProgram(const QString &programPath);
Q_INVOKABLE void startExternalWindow();
3.在qml端调用
ExternalWindow{
id:externalWindow
}
可以通过id直接调用函数
externalWindow.startExternalProgram("D:/QGC/Control_rtspV2.0/Json.exe")
externalWindow.startExternalWindow()
按照QGC说明文档 QGroundControlQmlGlobal中提供了qml中可以访问的接口