#ifndef SHAREDATA_H #define SHAREDATA_H #include "serialcontroller.h" #include "qserialproto.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(QQuickView *); 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 CloseSerial(); Q_INVOKABLE int TestLua(); Q_INVOKABLE int TestShowData(); Q_INVOKABLE int SaveLuaScript(QString); QString _txt = "hello world\r\n"; signals: void txtchanged(); void valueFromCpp(int val); private: SerialController *mSerialController; LuaDelegate mLua; QObject *mProtoDebug; QObject *mRootObj; QString mLuaScript; QQuickView *mView; }; #endif // SHAREDATA_H