no message

master
zcy 2021-04-17 02:27:32 +08:00
parent 4d59f92262
commit 51cf75dccd
7 changed files with 108 additions and 46 deletions

View File

@ -1,17 +1,18 @@
import QtQuick 2.0 import QtQuick 2.0
import QtQuick.Controls 2.14 import QtQuick.Controls 1.4
import QtQuick.Layouts 1.0 import QtQuick.Layouts 1.0
import QtQuick.Controls.Styles 1.4
Item { Item {
objectName: "ProtoDebug" objectName: "ProtoDebug"
width: parent.width - 80 // width: parent.width - 80
height: parent.height // height: parent.height
// width: 800 width: 800
// height: 600 height: 600
property var comlist: [] property var comlist: []
visible: true visible: true
property bool uart_open: false property bool uart_open: false
property var showbuf: ""
ColorAnimation { ColorAnimation {
from: "white" from: "white"
@ -19,52 +20,89 @@ Item {
duration: 200 duration: 200
} }
Rectangle{ Rectangle{
width: parent.width
height: parent.height
color: "#aeaeae" color: "#aeaeae"
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
anchors.fill: parent
scale: 1 scale: 1
transformOrigin: Item.Center transformOrigin: Item.Center
Label { GridLayout {
id: label width: parent.width
x: 49 height: parent.height
y: 30 x: 0
text: qsTr("lua脚本") y: 0
Layout.preferredHeight: 26 rows: 3
Layout.preferredWidth: 179 columns: 2
}
TextArea { Label {
id: text_output id: label
x: 8 text: qsTr("协议调试以及查看")
y: 75 Layout.columnSpan: 2
width: parent.width/2.1 font.pixelSize: 30
height: parent.height - 150 font.bold: true
color: "black" }
text: qsTr("")
} TextArea {
id: lua_script
Layout.preferredHeight: parent.height - 100
text: qsTr("")
font.pixelSize: 20
Layout.columnSpan: 1
Layout.preferredWidth: parent.width/2 - 20
style: TextAreaStyle {
textColor: "#333"
selectionColor: "steelblue"
selectedTextColor: "#eee"
backgroundColor: "#eee"
}
Layout.leftMargin: 10
TextEdit { }
id: lua_script TextArea {
x: 411 id: text_output
y: 75 Layout.preferredHeight: parent.height - 100
width: parent.width/2.1 text: qsTr("")
height: parent.height - 150 font.pixelSize: 20
text: qsTr("") Layout.columnSpan: 1
Layout.columnSpan: 2 Layout.preferredWidth: parent.width/2 - 20
style: TextAreaStyle {
textColor: "#333"
selectionColor: "steelblue"
selectedTextColor: "#eee"
backgroundColor: "#eee"
}
Layout.leftMargin: 10
font.pixelSize: 12 }
}
Button {
id: button Button {
x: 344 id: button
y: 540 text: qsTr("更新lua脚本")
text: qsTr("更新lua脚本") Layout.preferredHeight: 41
Layout.preferredHeight: 41 Layout.preferredWidth: 116
Layout.preferredWidth: 116 Layout.columnSpan: 2
Layout.leftMargin: parent.width/2 - 41
Layout.bottomMargin: 10
onClicked: {
DataWrap.TestShowData("dsads")
}
}
} }
} }
function addString(str){
showbuf += str
text_output.text = showbuf;
}
} }
/*##^##
Designer {
D{i:2;anchors_height:600;anchors_width:800}
}
##^##*/

View File

@ -1,7 +1,5 @@
#include "lua_bind.h" #include "lua_bind.h"
int LuaShowData(lua_State *vm) int LuaShowData(lua_State *vm)
{ {
// 获取函数参数:从栈底取一个参数 // 获取函数参数:从栈底取一个参数

View File

@ -7,7 +7,7 @@ extern "C" {
#include "lualib.h" #include "lualib.h"
} }
// 在界面中显示数据
int LuaShowData(lua_State *); int LuaShowData(lua_State *);
#endif // LUA_BIND_H #endif // LUA_BIND_H

View File

@ -43,6 +43,10 @@ int main(int argc, char *argv[])
view.show(); view.show();
QObject *qmlObject = view.findChild<QObject*>("SerialSelect",Qt::FindChildOption::FindChildrenRecursively); QObject *qmlObject = view.findChild<QObject*>("SerialSelect",Qt::FindChildOption::FindChildrenRecursively);
qmlObject->setProperty("comlist",comList); qmlObject->setProperty("comlist",comList);
QObject *protoDebugObj = view.findChild<QObject*>("ProtoDebug",Qt::FindChildOption::FindChildrenRecursively);
if(nullptr != protoDebugObj){
gGlobal.SetProtoDebug(protoDebugObj);
}
return app.exec(); return app.exec();
} }

View File

@ -25,6 +25,11 @@ public slots:
void ReadyRead(); void ReadyRead();
void AboutClose(); void AboutClose();
public: public:
typedef class {
public:
virtual int OnDataRecv();
}SerialListener;
typedef enum { typedef enum {
ERROR_OPEN = -1, ERROR_OPEN = -1,
ERROR_SEND = -2, ERROR_SEND = -2,

View File

@ -32,3 +32,16 @@ int ShareData::TestLua()
{ {
mLua.OnDataRecv(); mLua.OnDataRecv();
} }
int ShareData::TestShowData()
{
if(nullptr != mProtoDebug){
QMetaObject::invokeMethod(mProtoDebug, "addString",Q_ARG(QVariant, QString("test\r\n")));
}
return 0;
}
void ShareData::SetProtoDebug(QObject *obj)
{
this->mProtoDebug = obj;
}

View File

@ -2,6 +2,8 @@
#define SHAREDATA_H #define SHAREDATA_H
#include "serialcontroller.h" #include "serialcontroller.h"
#include "qserialproto.h"
#include <QObject> #include <QObject>
#include <QDebug> #include <QDebug>
#include "lua_wraper.h" #include "lua_wraper.h"
@ -31,11 +33,12 @@ public:
Q_INVOKABLE int OpenUart(QString port,QString baudRate,QString dataBits,QString stopBits, Q_INVOKABLE int OpenUart(QString port,QString baudRate,QString dataBits,QString stopBits,
QString flow); QString flow);
Q_INVOKABLE int CloseSerial(); Q_INVOKABLE int CloseSerial();
Q_INVOKABLE int TestLua(); Q_INVOKABLE int TestLua();
Q_INVOKABLE int TestShowData();
QString _txt = "hello world\r\n"; QString _txt = "hello world\r\n";
void SetProtoDebug(QObject * );
signals: signals:
void txtchanged(); void txtchanged();
void valueFromCpp(int val); void valueFromCpp(int val);
@ -43,6 +46,7 @@ signals:
private: private:
SerialController *mSerialController; SerialController *mSerialController;
LuaDelegate mLua; LuaDelegate mLua;
QObject *mProtoDebug;
}; };
#endif // SHAREDATA_H #endif // SHAREDATA_H