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

View File

@ -119,7 +119,6 @@ Item {
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
@ -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 "mainwindow.h"
#define test1 293
int main(int argc, char *argv[])
{
qDebug()<<test1;
QApplication app(argc, argv);
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
MainWindow w;
w.setWindowTitle("协议调试器");
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();
}

View File

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

View File

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

View File

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

View File

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

View File

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