no message

master
zcy 2021-07-19 23:52:38 +08:00
parent 2ee284652e
commit 08e7257574
8 changed files with 66 additions and 40 deletions

View File

@ -44,15 +44,25 @@ Item {
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
font.pointSize: 20 font.pointSize: 20
} }
TextEdit { TextEdit {
id: port id: port
Layout.leftMargin: 20 Layout.leftMargin: 20
width: 80 Layout.topMargin: 20
width: 233
height: 40 height: 40
text: qsTr("9001") text: qsTr("9001")
font.italic: false
font.bold: true
Layout.columnSpan: 2
Layout.preferredHeight: 33
Layout.preferredWidth: 233
selectionColor: "#f0f0f1" selectionColor: "#f0f0f1"
cursorVisible: true cursorVisible: true
font.pixelSize: 18 font.pixelSize: 20
color: white
textMargin: 4
} }
RadioButton { RadioButton {
id: isServer id: isServer
@ -138,6 +148,7 @@ Item {
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
font.pointSize: 20 font.pointSize: 20
} }
TextEdit { TextEdit {
id: hostEdit id: hostEdit
Layout.leftMargin: 20 Layout.leftMargin: 20

View File

@ -119,7 +119,6 @@ Item {
onClicked: { onClicked: {
lua_script_text = lua_script.text lua_script_text = lua_script.text
let ret = DataWrap.saveLuaScript(lua_script_text) let ret = DataWrap.saveLuaScript(lua_script_text)
console.log(ret)
if(ret != 0){ if(ret != 0){
tip.text = "保存lua脚本失败" tip.text = "保存lua脚本失败"
tip.visible = true tip.visible = true
@ -150,6 +149,31 @@ Item {
} }
Rectangle {
Layout.preferredHeight: 41
Layout.preferredWidth: input.contentWidth<300 ? 300 : input.contentWidth + 10
color: "lightgrey"
border.color: "grey"
Layout.bottomMargin: 10
TextInput {
id: input
anchors.fill: parent
anchors.margins: 2
font.pointSize: 15
focus: true
}
}
Button {
id: button1
text: qsTr("执行命令")
Layout.bottomMargin: 10
onClicked: {
}
}
} }
} }
} }

View File

@ -15,24 +15,15 @@
#include "lua_wraper.h" #include "lua_wraper.h"
#include "mainwindow.h" #include "mainwindow.h"
#define test1 293
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
qDebug()<<test1;
QApplication app(argc, argv); QApplication app(argc, argv);
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
MainWindow w; MainWindow w;
w.setWindowTitle("协议调试器"); w.setWindowTitle("协议调试器");
w.show(); w.show();
// QQuickWidget *m_quickWidget=new QQuickWidget();
// QUrl source("qrc:/main.qml");
// m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView );
// m_quickWidget->setSource(source);
// m_quickWidget->rootContext()->setContextProperty("DataWrap",&gGlobal);
// m_quickWidget->show();
// gGlobal.SetQuickView(m_quickWidget);
return app.exec(); return app.exec();
} }

View File

@ -39,7 +39,6 @@ Rectangle {
proto_debug.visible = false proto_debug.visible = false
} }
background: Image { background: Image {
anchors.fill: parent
source: "qrc:///res/serial.svg" source: "qrc:///res/serial.svg"
} }
} }
@ -62,7 +61,6 @@ Rectangle {
} }
background: Image { background: Image {
anchors.fill: parent
source: "qrc:///res/net.svg" source: "qrc:///res/net.svg"
} }
onPressed:{ onPressed:{
@ -93,10 +91,8 @@ Rectangle {
DataWrap.getValFromQml(1) DataWrap.getValFromQml(1)
} }
background: Image { background: Image {
anchors.fill: parent
source: "qrc:///res/proto.svg" source: "qrc:///res/proto.svg"
} }
} }
Text { Text {
id: label_proto id: label_proto
@ -121,7 +117,6 @@ Rectangle {
DataWrap.getValFromQml(1) DataWrap.getValFromQml(1)
} }
background: Image { background: Image {
anchors.fill: parent
source: "qrc:///res/proto.svg" source: "qrc:///res/proto.svg"
} }

View File

@ -8,7 +8,7 @@
#include "sharedata.h" #include "sharedata.h"
#include <QLayout> #include <QLayout>
ShareData gGlobal; QmlShareData gGlobal;
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
@ -22,10 +22,8 @@ MainWindow::MainWindow(QWidget *parent) :
m_quickWidget->setSource(source); m_quickWidget->setSource(source);
m_quickWidget->rootContext()->setContextProperty("DataWrap",&gGlobal); m_quickWidget->rootContext()->setContextProperty("DataWrap",&gGlobal);
gGlobal.SetQuickView(m_quickWidget); gGlobal.SetQuickView(m_quickWidget);
ui->centralwidget->layout()->addWidget(m_quickWidget); ui->centralwidget->layout()->addWidget(m_quickWidget);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()

View File

@ -16,6 +16,11 @@
<height>600</height> <height>600</height>
</size> </size>
</property> </property>
<property name="font">
<font>
<family>Arial</family>
</font>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>MainWindow</string> <string>MainWindow</string>
</property> </property>

View File

@ -6,7 +6,8 @@
#include <QQuickItem> #include <QQuickItem>
#include <QQmlContext> #include <QQmlContext>
ShareData::ShareData(QObject *parent) : QObject(parent),
QmlShareData::QmlShareData(QObject *parent) : QObject(parent),
m_qml_view_(nullptr), m_qml_view_(nullptr),
m_luavm_status_(false) m_luavm_status_(false)
{ {
@ -25,7 +26,7 @@ ShareData::ShareData(QObject *parent) : QObject(parent),
} }
} }
int ShareData::SetQuickView(QQuickWidget *view) int QmlShareData::SetQuickView(QQuickWidget *view)
{ {
QStringList comList; QStringList comList;
const auto infos = QSerialPortInfo::availablePorts(); const auto infos = QSerialPortInfo::availablePorts();
@ -47,20 +48,20 @@ int ShareData::SetQuickView(QQuickWidget *view)
} }
int ShareData::OnDataRecv(QByteArray arr) int QmlShareData::OnDataRecv(QByteArray arr)
{ {
if(m_luavm_status_) if(m_luavm_status_)
m_lua_.OnSerialData(QString(arr)); m_lua_.OnSerialData(QString(arr));
} }
int ShareData::ShowDataInQML(QString x) int QmlShareData::ShowDataInQML(QString x)
{ {
if(nullptr != m_qml_protodebug_){ if(nullptr != m_qml_protodebug_){
QMetaObject::invokeMethod(m_qml_protodebug_, "addString",Q_ARG(QVariant, x)); QMetaObject::invokeMethod(m_qml_protodebug_, "addString",Q_ARG(QVariant, x));
} }
} }
int ShareData::SendUartData(const char *data) int QmlShareData::SendUartData(const char *data)
{ {
if(nullptr != data){ if(nullptr != data){
this->m_serial_controller_->SendData((char *)data,strlen(data)); this->m_serial_controller_->SendData((char *)data,strlen(data));
@ -69,7 +70,7 @@ int ShareData::SendUartData(const char *data)
return -1; return -1;
} }
int ShareData::openUart(QString port, QString baudRate, QString dataBits, QString stopBits, QString flow) int QmlShareData::openUart(QString port, QString baudRate, QString dataBits, QString stopBits, QString flow)
{ {
if(m_serial_controller_->OpenSerial(port,baudRate,dataBits,stopBits,flow) == 0){ if(m_serial_controller_->OpenSerial(port,baudRate,dataBits,stopBits,flow) == 0){
m_serial_controller_->SetListener(this); m_serial_controller_->SetListener(this);
@ -79,7 +80,7 @@ int ShareData::openUart(QString port, QString baudRate, QString dataBits, QStrin
return -1; return -1;
} }
int ShareData::openNetwork(QString ip, unsigned int port, bool is_ws,int type) int QmlShareData::openNetwork(QString ip, unsigned int port, bool is_ws,int type)
{ {
if(type == NetworkController::TYPE_TCP_CLIENT){ if(type == NetworkController::TYPE_TCP_CLIENT){
@ -103,12 +104,12 @@ int ShareData::openNetwork(QString ip, unsigned int port, bool is_ws,int type)
return -1; return -1;
} }
int ShareData::closeNetwork() int QmlShareData::closeNetwork()
{ {
m_network_->Close(); m_network_->Close();
} }
int ShareData::closeSerial() int QmlShareData::closeSerial()
{ {
if(m_serial_controller_->CloseSerial() == 0){ if(m_serial_controller_->CloseSerial() == 0){
qDebug()<<"close serial ok"; qDebug()<<"close serial ok";
@ -118,12 +119,13 @@ int ShareData::closeSerial()
return -1; return -1;
} }
int ShareData::TestLua() int QmlShareData::TestLua()
{ {
m_lua_.OnSerialData("ss"); m_lua_.OnSerialData("ceshi");
return 0;
} }
int ShareData::TestShowData() int QmlShareData::TestShowData()
{ {
if(nullptr != m_qml_protodebug_){ if(nullptr != m_qml_protodebug_){
QMetaObject::invokeMethod(m_qml_protodebug_, "addString",Q_ARG(QVariant, QString("test\r\n"))); QMetaObject::invokeMethod(m_qml_protodebug_, "addString",Q_ARG(QVariant, QString("test\r\n")));
@ -131,7 +133,7 @@ int ShareData::TestShowData()
return 0; return 0;
} }
int ShareData::updateLuaScript(QString str) int QmlShareData::updateLuaScript(QString str)
{ {
qDebug()<<QThread::currentThreadId(); qDebug()<<QThread::currentThreadId();
m_lua_string = str; m_lua_string = str;
@ -146,7 +148,7 @@ int ShareData::updateLuaScript(QString str)
return 0; return 0;
} }
int ShareData::saveLuaScript(QString s) int QmlShareData::saveLuaScript(QString s)
{ {
QFile file("Test.lua"); //---打开文件 QFile file("Test.lua"); //---打开文件
if (file.open(QIODevice::WriteOnly) ) if (file.open(QIODevice::WriteOnly) )
@ -162,12 +164,12 @@ int ShareData::saveLuaScript(QString s)
return 0; return 0;
} }
bool ShareData::luaStatus() bool QmlShareData::luaStatus()
{ {
return m_luavm_status_; return m_luavm_status_;
} }
void ShareData::on_network_data_recv(){ void QmlShareData::on_network_data_recv(){
qDebug()<<"recv data"; qDebug()<<"recv data";
char dat[4096] = {0}; char dat[4096] = {0};
auto ret = this->m_network_->ReadData((int8_t * )dat); auto ret = this->m_network_->ReadData((int8_t * )dat);

View File

@ -9,17 +9,17 @@
#include "lua_wraper.h" #include "lua_wraper.h"
#include <QtQuickWidgets/QQuickWidget> #include <QtQuickWidgets/QQuickWidget>
class ShareData; class QmlShareData;
extern ShareData gGlobal; extern QmlShareData gGlobal;
// 桥接Lua虚拟机和qml界面 // 桥接Lua虚拟机和qml界面
class ShareData : public QObject ,SerialController::SerialListener class QmlShareData : public QObject ,SerialController::SerialListener
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString _txt READ rtxt WRITE settxt NOTIFY txtchanged) Q_PROPERTY(QString _txt READ rtxt WRITE settxt NOTIFY txtchanged)
public: public:
explicit ShareData(QObject *parent = nullptr); explicit QmlShareData(QObject *parent = nullptr);
int SetQuickView(QQuickWidget *); int SetQuickView(QQuickWidget *);
QString rtxt() const{ QString rtxt() const{
return _txt; return _txt;