#ifndef SHAREDATA_H #define SHAREDATA_H #include "serialcontroller.h" #include "qserialproto.h" #include "network_controller.h" #include #include #include "lua_wraper.h" #include class ShareData; extern ShareData gGlobal; // 桥接Lua虚拟机和qml界面 class ShareData : public QObject ,SerialController::SerialListener { Q_OBJECT Q_PROPERTY(QString _txt READ rtxt WRITE settxt NOTIFY txtchanged) public: explicit ShareData(QObject *parent = nullptr); int SetQuickView(QQuickWidget *); QString rtxt() const{ return _txt; } void settxt(QString s){ _txt = s; emit txtchanged(); } int OnDataRecv(QByteArray); int ShowDataInQML(QString x); int SendUartData(const char *); Q_INVOKABLE void getValFromQml(int v) { qDebug() << "value from qml is :" << v; emit valueFromCpp(456); } Q_INVOKABLE int openUart(QString port,QString baudRate,QString dataBits,QString stopBits, QString flow); Q_INVOKABLE int openNetwork(QString ip,unsigned int port,bool is_ws,int type); Q_INVOKABLE int closeNetwork(); Q_INVOKABLE int closeSerial(); Q_INVOKABLE int TestLua(); Q_INVOKABLE int TestShowData(); Q_INVOKABLE int updateLuaScript(QString); Q_INVOKABLE int saveLuaScript(QString); Q_INVOKABLE bool luaStatus(); QString _txt = "hello world\r\n"; signals: void txtchanged(); void valueFromCpp(int val); private: NetworkController *m_network_; SerialController *m_serial_controller_; LuaDelegate m_lua_; QObject *m_qml_protodebug_; QObject *m_root_obj_; bool m_luavm_status_; QString m_lua_string; QQuickWidget *m_qml_view_; }; #endif // SHAREDATA_H