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.Controls 2.14
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.0
import QtQuick.Controls.Styles 1.4
Item {
objectName: "ProtoDebug"
width: parent.width - 80
height: parent.height
// width: 800
// height: 600
// width: parent.width - 80
// height: parent.height
width: 800
height: 600
property var comlist: []
visible: true
property bool uart_open: false
property var showbuf: ""
ColorAnimation {
from: "white"
@ -19,52 +20,89 @@ Item {
duration: 200
}
Rectangle{
width: parent.width
height: parent.height
color: "#aeaeae"
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
anchors.fill: parent
scale: 1
transformOrigin: Item.Center
Label {
id: label
x: 49
y: 30
text: qsTr("lua脚本")
Layout.preferredHeight: 26
Layout.preferredWidth: 179
}
GridLayout {
width: parent.width
height: parent.height
x: 0
y: 0
rows: 3
columns: 2
TextArea {
id: text_output
x: 8
y: 75
width: parent.width/2.1
height: parent.height - 150
color: "black"
text: qsTr("")
Label {
id: label
text: qsTr("协议调试以及查看")
Layout.columnSpan: 2
font.pixelSize: 30
font.bold: true
}
}
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
x: 411
y: 75
width: parent.width/2.1
height: parent.height - 150
text: qsTr("")
Layout.columnSpan: 2
}
TextArea {
id: text_output
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
font.pixelSize: 12
}
}
Button {
id: button
x: 344
y: 540
text: qsTr("更新lua脚本")
Layout.preferredHeight: 41
Layout.preferredWidth: 116
Button {
id: button
text: qsTr("更新lua脚本")
Layout.preferredHeight: 41
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"
int LuaShowData(lua_State *vm)
{
// 获取函数参数:从栈底取一个参数

View File

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

View File

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

View File

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

View File

@ -32,3 +32,16 @@ int ShareData::TestLua()
{
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
#include "serialcontroller.h"
#include "qserialproto.h"
#include <QObject>
#include <QDebug>
#include "lua_wraper.h"
@ -31,11 +33,12 @@ public:
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();
QString _txt = "hello world\r\n";
void SetProtoDebug(QObject * );
signals:
void txtchanged();
void valueFromCpp(int val);
@ -43,6 +46,7 @@ signals:
private:
SerialController *mSerialController;
LuaDelegate mLua;
QObject *mProtoDebug;
};
#endif // SHAREDATA_H