diff --git a/protoDebuger/NetSelect.qml b/protoDebuger/NetSelect.qml index 4201839..ae2cef6 100644 --- a/protoDebuger/NetSelect.qml +++ b/protoDebuger/NetSelect.qml @@ -83,7 +83,7 @@ Item { id: label7 Layout.leftMargin: 20 Layout.topMargin: 20 - text: qsTr("协议选择:") + text: "协议选择:" Layout.preferredHeight: 40 renderType: Text.QtRendering Layout.preferredWidth: 125 diff --git a/protoDebuger/TcpSwarm.qml b/protoDebuger/TcpSwarm.qml new file mode 100644 index 0000000..80b2492 --- /dev/null +++ b/protoDebuger/TcpSwarm.qml @@ -0,0 +1,175 @@ +import QtQuick 2.0 +import QtQuick.Controls 2.14 +import QtQuick.Layouts 1.0 + + +Item { + objectName: "TcpSwarm" + width: 800 + height: 600 + + property var comlist: [] + visible: true + property bool uart_open: false + property var showbuf: "" + property var lua_script_text: "" + + ColorAnimation { + from: "white" + to: "black" + duration: 200 + } + Rectangle{ + color: "#aeaeae" + anchors.rightMargin: 0 + anchors.bottomMargin: 0 + anchors.leftMargin: 0 + anchors.topMargin: 0 + anchors.fill: parent + scale: 1 + transformOrigin: Item.Center + + GridLayout { + width: parent.width + height: parent.height + x: 0 + y: 0 + rows: 3 + columns: 2 + + Label { + id: label + text: qsTr("lua脚本:") + Layout.columnSpan: 1 + font.pixelSize: 30 + font.bold: true + } + Label { + id: label2 + text: qsTr("输出:") + Layout.columnSpan: 1 + font.pixelSize: 30 + font.bold: true + } + Flickable { + id: flick + Layout.preferredHeight: parent.height - 100 + Layout.preferredWidth: parent.width/2 - 20 + Layout.columnSpan: 1 + + contentWidth: lua_script.paintedWidth + contentHeight: lua_script.paintedHeight + clip: true + Layout.leftMargin: 10 + + ColorAnimation { + from: "white" + to: "white" + duration: 200 + } + function ensureVisible(r) + { + if (contentX >= r.x) + contentX = r.x; + else if (contentX+width <= r.x+r.width) + contentX = r.x+r.width-width; + if (contentY >= r.y) + contentY = r.y; + else if (contentY+height <= r.y+r.height) + contentY = r.y+r.height-height; + } + + TextEdit { + id: lua_script + focus: true + text: lua_script_text + font.pixelSize: 20 + color: "red" + selectByMouse : true + wrapMode: TextEdit.Wrap + onCursorRectangleChanged: flick.ensureVisible(cursorRectangle) + } + } + + TextArea { + id: text_output + Layout.preferredHeight: parent.height - 100 + text: qsTr("") + font.pixelSize: 20 + Layout.columnSpan: 1 + Layout.preferredWidth: parent.width/2 - 20 + background: Rectangle { + border.color: text_output.enabled ? "#21be2b" : "transparent" + } + Layout.leftMargin: 10 + + } + RowLayout{ + visible: true + Layout.columnSpan: 2 + Button { + id: button2 + text: qsTr("保存lua脚本") + Layout.preferredHeight: 41 + Layout.preferredWidth: 116 + Layout.leftMargin: 15 + Layout.bottomMargin: 10 + + onClicked: { + lua_script_text = lua_script.text + let ret = DataWrap.saveLuaScript(lua_script_text) + console.log(ret) + if(ret != 0){ + tip.text = "保存lua脚本失败" + tip.visible = true + return + } + tip.text = "保存lua脚本成功" + tip.visible = true + } + } + Button { + id: button + text: qsTr("更新lua脚本") + Layout.preferredHeight: 41 + Layout.preferredWidth: 116 + Layout.bottomMargin: 10 + + onClicked: { + lua_script_text = lua_script.text + let ret = DataWrap.updateLuaScript(lua_script_text) + if(ret != 0){ + tip.text = "更新lua脚本失败" + tip.visible = true + return + } + tip.text = "更新lua脚本成功" + tip.visible = true + } + + } + + } + } + } + ToolTip { + id: tip + text: qsTr("") + visible: false + contentItem: Text { + text: tip.text + font: tip.font + color: "#21be2b" + } + + background: Rectangle { + border.color: "#21be2b" + } + delay: 100 + timeout: 1000 + } + function addString(str){ + showbuf += str; + text_output.text = showbuf; + } +} diff --git a/protoDebuger/main.cpp b/protoDebuger/main.cpp index cd1b15e..359fe78 100644 --- a/protoDebuger/main.cpp +++ b/protoDebuger/main.cpp @@ -16,10 +16,11 @@ ShareData gGlobal; - +#define test1 293 int main(int argc, char *argv[]) { + qDebug()<connectToHost(ip,port,QIODevice::ReadWrite); + qDebug()<state(); if(mTcp->state() == QAbstractSocket::ConnectedState) mState = true; } @@ -95,7 +96,12 @@ int NetworkController::Close() delete mCnn; } if(mType == TYPE_TCP_CLIENT){ - mCnn->close(); + qDebug()<<(((QTcpSocket*)mTcp)->state()); + qDebug()<<"disconnected"<bytesAvailable()<bytesToWrite(); + ((QTcpSocket*)mTcp)->disconnectFromHost(); + if(((QTcpSocket*)mTcp)->waitForDisconnected(3000)); + mTcp->close(); + delete mTcp; } mState = false; return 0; diff --git a/protoDebuger/qml.qrc b/protoDebuger/qml.qrc index 30dbee3..be626f4 100644 --- a/protoDebuger/qml.qrc +++ b/protoDebuger/qml.qrc @@ -7,5 +7,6 @@ SerialSelect.qml NetSelect.qml ProtoDebug.qml + TcpSwarm.qml diff --git a/protoDebuger/sharedata.h b/protoDebuger/sharedata.h index c9a797a..663bbe8 100644 --- a/protoDebuger/sharedata.h +++ b/protoDebuger/sharedata.h @@ -33,7 +33,6 @@ public: int SendUartData(const char *); Q_INVOKABLE void getValFromQml(int v) { - qDebug() << "value from qml is :" << v; emit valueFromCpp(456); }