From 50d4e9ab0a0943700adb6513540108ef759cfd6c Mon Sep 17 00:00:00 2001 From: feiyangqingyun Date: Wed, 27 Apr 2022 09:24:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dascii=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- third/3rd_qcustomplot/3rd_qcustomplot.pri | 7 +++++- tool/comtool/api/quihelperdata.cpp | 26 ++++++++++++++++------- tool/comtool/form/frmcomtool.cpp | 3 +-- tool/comtool/form/frmcomtool.h | 2 ++ tool/netserver/api/quihelperdata.cpp | 26 ++++++++++++++++------- tool/nettool/api/quihelperdata.cpp | 26 ++++++++++++++++------- 6 files changed, 63 insertions(+), 27 deletions(-) diff --git a/third/3rd_qcustomplot/3rd_qcustomplot.pri b/third/3rd_qcustomplot/3rd_qcustomplot.pri index dbeebc1..ac9160f 100644 --- a/third/3rd_qcustomplot/3rd_qcustomplot.pri +++ b/third/3rd_qcustomplot/3rd_qcustomplot.pri @@ -2,19 +2,23 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += printsupport greaterThan(QT_MAJOR_VERSION, 4): CONFIG += c++11 #lessThan(QT_MAJOR_VERSION, 5): QMAKE_CXXFLAGS += -std=c++11 +#没有定义任何版本则默认采用2.0 !contains(DEFINES, qcustomplot_v1_3) { !contains(DEFINES, qcustomplot_v2_0) { !contains(DEFINES, qcustomplot_v2_1) { DEFINES += qcustomplot_v2_0 }}} +#定义了2.0版本在Qt5以上采用2.1 +contains(DEFINES, qcustomplot_v2_0) { !contains(DEFINES, qcustomplot_v2_1) { greaterThan(QT_MAJOR_VERSION, 4) { DEFINES -= qcustomplot_v1_3 DEFINES -= qcustomplot_v2_0 DEFINES += qcustomplot_v2_1 -}} +}}} +#根据定义的版本引入文件 contains(DEFINES, qcustomplot_v1_3) { INCLUDEPATH += $$PWD/v1_3 HEADERS += $$PWD/v1_3/qcustomplot.h @@ -26,6 +30,7 @@ HEADERS += $$PWD/v2_0/qcustomplot.h SOURCES += $$PWD/v2_0/qcustomplot.cpp } else { INCLUDEPATH += $$PWD/v2_1 +#引入对应修复不支持Qt6的头文件 greaterThan(QT_MAJOR_VERSION, 5) { HEADERS += $$PWD/v2_1_6/qcustomplot.h } else { diff --git a/tool/comtool/api/quihelperdata.cpp b/tool/comtool/api/quihelperdata.cpp index 0d26a90..62b7f05 100644 --- a/tool/comtool/api/quihelperdata.cpp +++ b/tool/comtool/api/quihelperdata.cpp @@ -26,7 +26,7 @@ QString QUIHelperData::strHexToStrBin(const QString &strHex) uchar len = bin.length(); if (len < 8) { - for (int i = 0; i < 8 - len; i++) { + for (int i = 0; i < 8 - len; ++i) { bin = "0" + bin; } } @@ -39,7 +39,7 @@ QString QUIHelperData::decimalToStrBin1(int decimal) QString bin = QString::number(decimal, 2); uchar len = bin.length(); if (len <= 8) { - for (int i = 0; i < 8 - len; i++) { + for (int i = 0; i < 8 - len; ++i) { bin = "0" + bin; } } @@ -52,7 +52,7 @@ QString QUIHelperData::decimalToStrBin2(int decimal) QString bin = QString::number(decimal, 2); uchar len = bin.length(); if (len <= 16) { - for (int i = 0; i < 16 - len; i++) { + for (int i = 0; i < 16 - len; ++i) { bin = "0" + bin; } } @@ -184,9 +184,14 @@ QString QUIHelperData::getXorEncryptDecrypt(const QString &value, char key) key = 127; } + //大概从5.9版本输出的加密密码字符串前面会加上 @String 字符 QString result = value; + if (result.startsWith("@String")) { + result = result.mid(8, result.length() - 9); + } + int count = result.count(); - for (int i = 0; i < count; i++) { + for (int i = 0; i < count; ++i) { result[i] = QChar(result.at(i).toLatin1() ^ key); } return result; @@ -196,7 +201,7 @@ uchar QUIHelperData::getOrCode(const QByteArray &data) { int len = data.length(); uchar result = 0; - for (int i = 0; i < len; i++) { + for (int i = 0; i < len; ++i) { result ^= data.at(i); } @@ -207,7 +212,7 @@ uchar QUIHelperData::getCheckCode(const QByteArray &data) { int len = data.length(); uchar temp = 0; - for (uchar i = 0; i < len; i++) { + for (uchar i = 0; i < len; ++i) { temp += data.at(i); } @@ -344,7 +349,7 @@ QString QUIHelperData::byteArrayToAsciiStr(const QByteArray &data) QString temp; int len = data.size(); - for (int i = 0; i < len; i++) { + for (int i = 0; i < len; ++i) { char byte = data.at(i); QString value = listChar.value(byte); if (!value.isEmpty()) { @@ -370,7 +375,7 @@ QByteArray QUIHelperData::asciiStrToByteArray(const QString &data) QStringList list = data.split("\\"); int count = list.count(); - for (int i = 1; i < count; i++) { + for (int i = 1; i < count; ++i) { QString str = list.at(i); int key = 0; if (str.contains("x")) { @@ -382,6 +387,11 @@ QByteArray QUIHelperData::asciiStrToByteArray(const QString &data) buffer.append(key); } + //可能是纯字符串不带控制字符 + if (buffer.size() == 0) { + buffer = data.toUtf8(); + } + return buffer; } diff --git a/tool/comtool/form/frmcomtool.cpp b/tool/comtool/form/frmcomtool.cpp index 6d110c8..a4ed141 100644 --- a/tool/comtool/form/frmcomtool.cpp +++ b/tool/comtool/form/frmcomtool.cpp @@ -386,8 +386,7 @@ void frmComTool::sendData(QString data) void frmComTool::saveData() { QString tempData = ui->txtMain->toPlainText(); - - if (tempData == "") { + if (tempData.isEmpty()) { return; } diff --git a/tool/comtool/form/frmcomtool.h b/tool/comtool/form/frmcomtool.h index 8ba400c..e25f0cb 100644 --- a/tool/comtool/form/frmcomtool.h +++ b/tool/comtool/form/frmcomtool.h @@ -58,9 +58,11 @@ private slots: void on_btnStopShow_clicked(); void on_btnSendCount_clicked(); void on_btnReceiveCount_clicked(); + void on_btnClear_clicked(); void on_btnData_clicked(); void on_btnStart_clicked(); + void on_ckAutoSend_stateChanged(int arg1); void on_ckAutoSave_stateChanged(int arg1); }; diff --git a/tool/netserver/api/quihelperdata.cpp b/tool/netserver/api/quihelperdata.cpp index 0d26a90..62b7f05 100644 --- a/tool/netserver/api/quihelperdata.cpp +++ b/tool/netserver/api/quihelperdata.cpp @@ -26,7 +26,7 @@ QString QUIHelperData::strHexToStrBin(const QString &strHex) uchar len = bin.length(); if (len < 8) { - for (int i = 0; i < 8 - len; i++) { + for (int i = 0; i < 8 - len; ++i) { bin = "0" + bin; } } @@ -39,7 +39,7 @@ QString QUIHelperData::decimalToStrBin1(int decimal) QString bin = QString::number(decimal, 2); uchar len = bin.length(); if (len <= 8) { - for (int i = 0; i < 8 - len; i++) { + for (int i = 0; i < 8 - len; ++i) { bin = "0" + bin; } } @@ -52,7 +52,7 @@ QString QUIHelperData::decimalToStrBin2(int decimal) QString bin = QString::number(decimal, 2); uchar len = bin.length(); if (len <= 16) { - for (int i = 0; i < 16 - len; i++) { + for (int i = 0; i < 16 - len; ++i) { bin = "0" + bin; } } @@ -184,9 +184,14 @@ QString QUIHelperData::getXorEncryptDecrypt(const QString &value, char key) key = 127; } + //大概从5.9版本输出的加密密码字符串前面会加上 @String 字符 QString result = value; + if (result.startsWith("@String")) { + result = result.mid(8, result.length() - 9); + } + int count = result.count(); - for (int i = 0; i < count; i++) { + for (int i = 0; i < count; ++i) { result[i] = QChar(result.at(i).toLatin1() ^ key); } return result; @@ -196,7 +201,7 @@ uchar QUIHelperData::getOrCode(const QByteArray &data) { int len = data.length(); uchar result = 0; - for (int i = 0; i < len; i++) { + for (int i = 0; i < len; ++i) { result ^= data.at(i); } @@ -207,7 +212,7 @@ uchar QUIHelperData::getCheckCode(const QByteArray &data) { int len = data.length(); uchar temp = 0; - for (uchar i = 0; i < len; i++) { + for (uchar i = 0; i < len; ++i) { temp += data.at(i); } @@ -344,7 +349,7 @@ QString QUIHelperData::byteArrayToAsciiStr(const QByteArray &data) QString temp; int len = data.size(); - for (int i = 0; i < len; i++) { + for (int i = 0; i < len; ++i) { char byte = data.at(i); QString value = listChar.value(byte); if (!value.isEmpty()) { @@ -370,7 +375,7 @@ QByteArray QUIHelperData::asciiStrToByteArray(const QString &data) QStringList list = data.split("\\"); int count = list.count(); - for (int i = 1; i < count; i++) { + for (int i = 1; i < count; ++i) { QString str = list.at(i); int key = 0; if (str.contains("x")) { @@ -382,6 +387,11 @@ QByteArray QUIHelperData::asciiStrToByteArray(const QString &data) buffer.append(key); } + //可能是纯字符串不带控制字符 + if (buffer.size() == 0) { + buffer = data.toUtf8(); + } + return buffer; } diff --git a/tool/nettool/api/quihelperdata.cpp b/tool/nettool/api/quihelperdata.cpp index 0d26a90..62b7f05 100644 --- a/tool/nettool/api/quihelperdata.cpp +++ b/tool/nettool/api/quihelperdata.cpp @@ -26,7 +26,7 @@ QString QUIHelperData::strHexToStrBin(const QString &strHex) uchar len = bin.length(); if (len < 8) { - for (int i = 0; i < 8 - len; i++) { + for (int i = 0; i < 8 - len; ++i) { bin = "0" + bin; } } @@ -39,7 +39,7 @@ QString QUIHelperData::decimalToStrBin1(int decimal) QString bin = QString::number(decimal, 2); uchar len = bin.length(); if (len <= 8) { - for (int i = 0; i < 8 - len; i++) { + for (int i = 0; i < 8 - len; ++i) { bin = "0" + bin; } } @@ -52,7 +52,7 @@ QString QUIHelperData::decimalToStrBin2(int decimal) QString bin = QString::number(decimal, 2); uchar len = bin.length(); if (len <= 16) { - for (int i = 0; i < 16 - len; i++) { + for (int i = 0; i < 16 - len; ++i) { bin = "0" + bin; } } @@ -184,9 +184,14 @@ QString QUIHelperData::getXorEncryptDecrypt(const QString &value, char key) key = 127; } + //大概从5.9版本输出的加密密码字符串前面会加上 @String 字符 QString result = value; + if (result.startsWith("@String")) { + result = result.mid(8, result.length() - 9); + } + int count = result.count(); - for (int i = 0; i < count; i++) { + for (int i = 0; i < count; ++i) { result[i] = QChar(result.at(i).toLatin1() ^ key); } return result; @@ -196,7 +201,7 @@ uchar QUIHelperData::getOrCode(const QByteArray &data) { int len = data.length(); uchar result = 0; - for (int i = 0; i < len; i++) { + for (int i = 0; i < len; ++i) { result ^= data.at(i); } @@ -207,7 +212,7 @@ uchar QUIHelperData::getCheckCode(const QByteArray &data) { int len = data.length(); uchar temp = 0; - for (uchar i = 0; i < len; i++) { + for (uchar i = 0; i < len; ++i) { temp += data.at(i); } @@ -344,7 +349,7 @@ QString QUIHelperData::byteArrayToAsciiStr(const QByteArray &data) QString temp; int len = data.size(); - for (int i = 0; i < len; i++) { + for (int i = 0; i < len; ++i) { char byte = data.at(i); QString value = listChar.value(byte); if (!value.isEmpty()) { @@ -370,7 +375,7 @@ QByteArray QUIHelperData::asciiStrToByteArray(const QString &data) QStringList list = data.split("\\"); int count = list.count(); - for (int i = 1; i < count; i++) { + for (int i = 1; i < count; ++i) { QString str = list.at(i); int key = 0; if (str.contains("x")) { @@ -382,6 +387,11 @@ QByteArray QUIHelperData::asciiStrToByteArray(const QString &data) buffer.append(key); } + //可能是纯字符串不带控制字符 + if (buffer.size() == 0) { + buffer = data.toUtf8(); + } + return buffer; }