新增网络调试助手
parent
66e0d86b1a
commit
4c47589b1b
|
@ -1,4 +1,4 @@
|
|||
# QWidgetDemo
|
||||
# QWidgetDemo
|
||||
|
||||
#### 项目介绍
|
||||
用来存放一些QWidget相关的开源的demo,包括串口调试助手、网络调试助手、部分自定义控件、其他小demo等,会一直持续增加和更新,欢迎各位留言评论!
|
||||
|
@ -9,3 +9,5 @@
|
|||
3. flatui 模仿flatui类
|
||||
4. countcode 代码统计组件
|
||||
5. gifwidget 屏幕录制控件
|
||||
6. comtool 串口调试助手
|
||||
7. nettool 网络调试助手
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
HEADERS += \
|
||||
$$PWD/app.h \
|
||||
$$PWD/quiwidget.h \
|
||||
$$PWD/tcpserver.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/app.cpp \
|
||||
$$PWD/quiwidget.cpp \
|
||||
$$PWD/tcpserver.cpp
|
|
@ -0,0 +1,226 @@
|
|||
#include "app.h"
|
||||
#include "quiwidget.h"
|
||||
|
||||
QString App::ConfigFile = "config.ini";
|
||||
QString App::SendFileName = "send.txt";
|
||||
QString App::DeviceFileName = "device.txt";
|
||||
|
||||
int App::CurrentIndex = 0;
|
||||
|
||||
bool App::HexSendTcpClient = false;
|
||||
bool App::HexReceiveTcpClient = false;
|
||||
bool App::AsciiTcpClient = false;
|
||||
bool App::DebugTcpClient = false;
|
||||
bool App::AutoSendTcpClient = false;
|
||||
int App::IntervalTcpClient = 1000;
|
||||
QString App::TcpServerIP = "127.0.0.1";
|
||||
int App::TcpServerPort = 6000;
|
||||
|
||||
bool App::HexSendTcpServer = false;
|
||||
bool App::HexReceiveTcpServer = false;
|
||||
bool App::AsciiTcpServer = false;
|
||||
bool App::DebugTcpServer = false;
|
||||
bool App::AutoSendTcpServer = false;
|
||||
bool App::SelectAllTcpServer = false;
|
||||
int App::IntervalTcpServer = 1000;
|
||||
int App::TcpListenPort = 6000;
|
||||
|
||||
bool App::HexSendUdpServer = false;
|
||||
bool App::HexReceiveUdpServer = false;
|
||||
bool App::AsciiUdpServer = false;
|
||||
bool App::DebugUdpServer = false;
|
||||
bool App::AutoSendUdpServer = false;
|
||||
int App::IntervalUdpServer = 1000;
|
||||
int App::UdpListenPort = 6000;
|
||||
QString App::UdpServerIP = "127.0.0.1";
|
||||
int App::UdpServerPort = 6000;
|
||||
|
||||
void App::readConfig()
|
||||
{
|
||||
if (!checkConfig()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QSettings set(App::ConfigFile, QSettings::IniFormat);
|
||||
|
||||
set.beginGroup("AppConfig");
|
||||
App::CurrentIndex = set.value("CurrentIndex").toInt();
|
||||
set.endGroup();
|
||||
|
||||
set.beginGroup("TcpClientConfig");
|
||||
App::HexSendTcpClient = set.value("HexSendTcpClient").toBool();
|
||||
App::HexReceiveTcpClient = set.value("HexReceiveTcpClient").toBool();
|
||||
App::AsciiTcpClient = set.value("AsciiTcpClient").toBool();
|
||||
App::DebugTcpClient = set.value("DebugTcpClient").toBool();
|
||||
App::AutoSendTcpClient = set.value("AutoSendTcpClient").toBool();
|
||||
App::IntervalTcpClient = set.value("IntervalTcpClient").toInt();
|
||||
App::TcpServerIP = set.value("TcpServerIP").toString();
|
||||
App::TcpServerPort = set.value("TcpServerPort").toInt();
|
||||
set.endGroup();
|
||||
|
||||
set.beginGroup("TcpServerConfig");
|
||||
App::HexSendTcpServer = set.value("HexSendTcpServer").toBool();
|
||||
App::HexReceiveTcpServer = set.value("HexReceiveTcpServer").toBool();
|
||||
App::AsciiTcpServer = set.value("AsciiTcpServer").toBool();
|
||||
App::DebugTcpServer = set.value("DebugTcpServer").toBool();
|
||||
App::AutoSendTcpServer = set.value("AutoSendTcpServer").toBool();
|
||||
App::SelectAllTcpServer = set.value("SelectAllTcpServer").toBool();
|
||||
App::IntervalTcpServer = set.value("IntervalTcpServer").toInt();
|
||||
App::TcpListenPort = set.value("TcpListenPort").toInt();
|
||||
set.endGroup();
|
||||
|
||||
set.beginGroup("UdpServerConfig");
|
||||
App::HexSendUdpServer = set.value("HexSendUdpServer").toBool();
|
||||
App::HexReceiveUdpServer = set.value("HexReceiveUdpServer").toBool();
|
||||
App::AsciiUdpServer = set.value("AsciiUdpServer").toBool();
|
||||
App::DebugUdpServer = set.value("DebugUdpServer").toBool();
|
||||
App::AutoSendUdpServer = set.value("AutoSendUdpServer").toBool();
|
||||
App::IntervalUdpServer = set.value("IntervalUdpServer").toInt();
|
||||
App::UdpServerIP = set.value("UdpServerIP").toString();
|
||||
App::UdpServerPort = set.value("UdpServerPort").toInt();
|
||||
App::UdpListenPort = set.value("UdpListenPort").toInt();
|
||||
set.endGroup();
|
||||
}
|
||||
|
||||
void App::writeConfig()
|
||||
{
|
||||
QSettings set(App::ConfigFile, QSettings::IniFormat);
|
||||
|
||||
set.beginGroup("AppConfig");
|
||||
set.setValue("CurrentIndex", App::CurrentIndex);
|
||||
set.endGroup();
|
||||
|
||||
set.beginGroup("TcpClientConfig");
|
||||
set.setValue("HexSendTcpClient", App::HexSendTcpClient);
|
||||
set.setValue("HexReceiveTcpClient", App::HexReceiveTcpClient);
|
||||
set.setValue("DebugTcpClient", App::DebugTcpClient);
|
||||
set.setValue("AutoSendTcpClient", App::AutoSendTcpClient);
|
||||
set.setValue("IntervalTcpClient", App::IntervalTcpClient);
|
||||
set.setValue("TcpServerIP", App::TcpServerIP);
|
||||
set.setValue("TcpServerPort", App::TcpServerPort);
|
||||
set.endGroup();
|
||||
|
||||
set.beginGroup("TcpServerConfig");
|
||||
set.setValue("HexSendTcpServer", App::HexSendTcpServer);
|
||||
set.setValue("HexReceiveTcpServer", App::HexReceiveTcpServer);
|
||||
set.setValue("DebugTcpServer", App::DebugTcpServer);
|
||||
set.setValue("AutoSendTcpServer", App::AutoSendTcpServer);
|
||||
set.setValue("SelectAllTcpServer", App::SelectAllTcpServer);
|
||||
set.setValue("IntervalTcpServer", App::IntervalTcpServer);
|
||||
set.setValue("TcpListenPort", App::TcpListenPort);
|
||||
set.endGroup();
|
||||
|
||||
set.beginGroup("UdpServerConfig");
|
||||
set.setValue("HexSendUdpServer", App::HexSendUdpServer);
|
||||
set.setValue("HexReceiveUdpServer", App::HexReceiveUdpServer);
|
||||
set.setValue("DebugUdpServer", App::DebugUdpServer);
|
||||
set.setValue("AutoSendUdpServer", App::AutoSendUdpServer);
|
||||
set.setValue("IntervalUdpServer", App::IntervalUdpServer);
|
||||
set.setValue("UdpServerIP", App::UdpServerIP);
|
||||
set.setValue("UdpServerPort", App::UdpServerPort);
|
||||
set.setValue("UdpListenPort", App::UdpListenPort);
|
||||
set.endGroup();
|
||||
}
|
||||
|
||||
void App::newConfig()
|
||||
{
|
||||
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
|
||||
#endif
|
||||
writeConfig();
|
||||
}
|
||||
|
||||
bool App::checkConfig()
|
||||
{
|
||||
//如果配置文件大小为0,则以初始值继续运行,并生成配置文件
|
||||
QFile file(App::ConfigFile);
|
||||
if (file.size() == 0) {
|
||||
newConfig();
|
||||
return false;
|
||||
}
|
||||
|
||||
//如果配置文件不完整,则以初始值继续运行,并生成配置文件
|
||||
if (file.open(QFile::ReadOnly)) {
|
||||
bool ok = true;
|
||||
while (!file.atEnd()) {
|
||||
QString line = file.readLine();
|
||||
line = line.replace("\r", "");
|
||||
line = line.replace("\n", "");
|
||||
QStringList list = line.split("=");
|
||||
|
||||
if (list.count() == 2) {
|
||||
if (list.at(1) == "") {
|
||||
ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
newConfig();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
newConfig();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QStringList App::Intervals = QStringList();
|
||||
QStringList App::Datas = QStringList();
|
||||
QStringList App::Keys = QStringList();
|
||||
QStringList App::Values = QStringList();
|
||||
|
||||
void App::readSendData()
|
||||
{
|
||||
//读取发送数据列表
|
||||
App::Datas.clear();
|
||||
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(App::SendFileName);
|
||||
QFile file(fileName);
|
||||
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
|
||||
while (!file.atEnd()) {
|
||||
QString line = file.readLine();
|
||||
line = line.trimmed();
|
||||
line = line.replace("\r", "");
|
||||
line = line.replace("\n", "");
|
||||
if (!line.isEmpty()) {
|
||||
App::Datas.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
|
||||
void App::readDeviceData()
|
||||
{
|
||||
//读取转发数据列表
|
||||
App::Keys.clear();
|
||||
App::Values.clear();
|
||||
QString fileName = QString("%1/%2").arg(QUIHelper::appPath()).arg(App::DeviceFileName);
|
||||
QFile file(fileName);
|
||||
if (file.size() > 0 && file.open(QFile::ReadOnly | QIODevice::Text)) {
|
||||
while (!file.atEnd()) {
|
||||
QString line = file.readLine();
|
||||
line = line.trimmed();
|
||||
line = line.replace("\r", "");
|
||||
line = line.replace("\n", "");
|
||||
if (!line.isEmpty()) {
|
||||
QStringList list = line.split(";");
|
||||
QString key = list.at(0);
|
||||
QString value;
|
||||
for (int i = 1; i < list.count(); i++) {
|
||||
value += QString("%1;").arg(list.at(i));
|
||||
}
|
||||
|
||||
//去掉末尾分号
|
||||
value = value.mid(0, value.length() - 1);
|
||||
App::Keys.append(key);
|
||||
App::Values.append(value);
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
#ifndef APP_H
|
||||
#define APP_H
|
||||
|
||||
#include "head.h"
|
||||
|
||||
class App
|
||||
{
|
||||
public:
|
||||
static QString ConfigFile; //配置文件路径
|
||||
static QString SendFileName; //发送配置文件名
|
||||
static QString DeviceFileName; //模拟设备数据文件名
|
||||
|
||||
static int CurrentIndex; //当前索引
|
||||
|
||||
//TCP客户端配置参数
|
||||
static bool HexSendTcpClient; //16进制发送
|
||||
static bool HexReceiveTcpClient; //16进制接收
|
||||
static bool AsciiTcpClient; //ASCII模式
|
||||
static bool DebugTcpClient; //启用数据调试
|
||||
static bool AutoSendTcpClient; //自动发送数据
|
||||
static int IntervalTcpClient; //发送数据间隔
|
||||
static QString TcpServerIP; //服务器IP
|
||||
static int TcpServerPort; //服务器端口
|
||||
|
||||
//TCP服务器配置参数
|
||||
static bool HexSendTcpServer; //16进制发送
|
||||
static bool HexReceiveTcpServer; //16进制接收
|
||||
static bool AsciiTcpServer; //ASCII模式
|
||||
static bool DebugTcpServer; //启用数据调试
|
||||
static bool AutoSendTcpServer; //自动发送数据
|
||||
static bool SelectAllTcpServer; //选中所有
|
||||
static int IntervalTcpServer; //发送数据间隔
|
||||
static int TcpListenPort; //监听端口
|
||||
|
||||
//UDP服务器配置参数
|
||||
static bool HexSendUdpServer; //16进制发送
|
||||
static bool HexReceiveUdpServer; //16进制接收
|
||||
static bool AsciiUdpServer; //ASCII模式
|
||||
static bool DebugUdpServer; //启用数据调试
|
||||
static bool AutoSendUdpServer; //自动发送数据
|
||||
static int IntervalUdpServer; //发送数据间隔
|
||||
static QString UdpServerIP; //服务器IP
|
||||
static int UdpServerPort; //服务器端口
|
||||
static int UdpListenPort; //监听端口
|
||||
|
||||
//读写配置参数及其他操作
|
||||
static void readConfig(); //读取配置参数
|
||||
static void writeConfig(); //写入配置参数
|
||||
static void newConfig(); //以初始值新建配置文件
|
||||
static bool checkConfig(); //校验配置文件
|
||||
|
||||
static QStringList Intervals;
|
||||
static QStringList Datas;
|
||||
static QStringList Keys;
|
||||
static QStringList Values;
|
||||
static void readSendData();
|
||||
static void readDeviceData();
|
||||
};
|
||||
|
||||
#endif // APP_H
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,871 @@
|
|||
#ifndef QUIWIDGET_H
|
||||
#define QUIWIDGET_H
|
||||
|
||||
#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
|
||||
#define TIME qPrintable(QTime::currentTime().toString("HH:mm:ss"))
|
||||
#define QDATE qPrintable(QDate::currentDate().toString("yyyy-MM-dd"))
|
||||
#define QTIME qPrintable(QTime::currentTime().toString("HH-mm-ss"))
|
||||
#define DATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"))
|
||||
#define STRDATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss"))
|
||||
#define STRDATETIMEMS qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss-zzz"))
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#define NEWLINE "\r\n"
|
||||
#else
|
||||
#define NEWLINE "\n"
|
||||
#endif
|
||||
|
||||
#ifdef __arm__
|
||||
#define TitleMinSize 40
|
||||
#else
|
||||
#define TitleMinSize 30
|
||||
#endif
|
||||
|
||||
/**
|
||||
* QUI无边框窗体控件 作者:feiyangqingyun(QQ:517216493)
|
||||
* 1:内置 N >= 17 套精美样式,可直接切换,也可自定义样式路径
|
||||
* 2:可设置部件(左上角图标/最小化按钮/最大化按钮/关闭按钮)的图标或者图片及是否可见
|
||||
* 3:可集成设计师插件,直接拖曳使用,所见即所得
|
||||
* 4:如果需要窗体可拖动大小,设置 setSizeGripEnabled(true);
|
||||
* 5:可设置全局样式 setStyle
|
||||
* 6:可弹出消息框,可选阻塞模式和不阻塞,默认不阻塞 showMessageBoxInfo
|
||||
* 7:可弹出错误框,可选阻塞模式和不阻塞,默认不阻塞 showMessageBoxError
|
||||
* 8:可弹出询问框 showMessageBoxError
|
||||
* 9:可弹出右下角信息框 showTipBox
|
||||
* 10:可弹出输入框 showInputBox
|
||||
* 11:可弹出时间范围选择框 showDateSelect
|
||||
* 12:消息框支持设置倒计时关闭
|
||||
* 13:集成图形字体设置方法及根据指定文字获取图片
|
||||
* 14:集成设置窗体居中显示/设置翻译文件/设置编码/设置延时/设置系统时间等静态方法
|
||||
* 15:集成获取应用程序文件名/文件路径 等方法
|
||||
*/
|
||||
|
||||
#include "head.h"
|
||||
|
||||
#ifdef quc
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5,7,0))
|
||||
#include <QtDesigner/QDesignerExportWidget>
|
||||
#else
|
||||
#include <QtUiPlugin/QDesignerExportWidget>
|
||||
#endif
|
||||
|
||||
class QDESIGNER_WIDGET_EXPORT QUIWidget : public QDialog
|
||||
#else
|
||||
class QUIWidget : public QDialog
|
||||
#endif
|
||||
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(Style)
|
||||
Q_PROPERTY(QString title READ getTitle WRITE setTitle)
|
||||
Q_PROPERTY(Qt::Alignment alignment READ getAlignment WRITE setAlignment)
|
||||
Q_PROPERTY(bool minHide READ getMinHide WRITE setMinHide)
|
||||
Q_PROPERTY(bool exitAll READ getExitAll WRITE setExitAll)
|
||||
|
||||
public:
|
||||
//将部分对象作为枚举值暴露给外部
|
||||
enum Widget {
|
||||
Lab_Ico = 0, //左上角图标
|
||||
BtnMenu = 1, //下拉菜单按钮
|
||||
BtnMenu_Min = 2, //最小化按钮
|
||||
BtnMenu_Max = 3, //最大化按钮
|
||||
BtnMenu_Normal = 4, //还原按钮
|
||||
BtnMenu_Close = 5 //关闭按钮
|
||||
};
|
||||
|
||||
//样式枚举
|
||||
enum Style {
|
||||
Style_Silvery = 0, //银色样式
|
||||
Style_Blue = 1, //蓝色样式
|
||||
Style_LightBlue = 2, //淡蓝色样式
|
||||
Style_DarkBlue = 3, //深蓝色样式
|
||||
Style_Gray = 4, //灰色样式
|
||||
Style_LightGray = 5, //浅灰色样式
|
||||
Style_DarkGray = 6, //深灰色样式
|
||||
Style_Black = 7, //黑色样式
|
||||
Style_LightBlack = 8, //浅黑色样式
|
||||
Style_DarkBlack = 9, //深黑色样式
|
||||
Style_PSBlack = 10, //PS黑色样式
|
||||
Style_FlatBlack = 11, //黑色扁平样式
|
||||
Style_FlatWhite = 12, //白色扁平样式
|
||||
Style_FlatBlue = 13, //蓝色扁平样式
|
||||
Style_Purple = 14, //紫色样式
|
||||
Style_BlackBlue = 15, //黑蓝色样式
|
||||
Style_BlackVideo = 16 //视频监控黑色样式
|
||||
};
|
||||
|
||||
public:
|
||||
explicit QUIWidget(QWidget *parent = 0);
|
||||
~QUIWidget();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout4;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QToolButton *btnMenu;
|
||||
QPushButton *btnMenu_Min;
|
||||
QPushButton *btnMenu_Max;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widget;
|
||||
QVBoxLayout *verticalLayout3;
|
||||
|
||||
private:
|
||||
QString title; //标题
|
||||
Qt::Alignment alignment; //标题文本对齐
|
||||
bool minHide; //最小化隐藏
|
||||
bool exitAll; //退出整个程序
|
||||
QWidget *mainWidget; //主窗体对象
|
||||
|
||||
public:
|
||||
QLabel *getLabIco() const;
|
||||
QLabel *getLabTitle() const;
|
||||
QToolButton *getBtnMenu() const;
|
||||
QPushButton *getBtnMenuMin() const;
|
||||
QPushButton *getBtnMenuMax() const;
|
||||
QPushButton *getBtnMenuMClose() const;
|
||||
|
||||
QString getTitle() const;
|
||||
Qt::Alignment getAlignment() const;
|
||||
bool getMinHide() const;
|
||||
bool getExitAll() const;
|
||||
|
||||
QSize sizeHint() const;
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void changeStyle(); //更换样式
|
||||
|
||||
private slots:
|
||||
void on_btnMenu_Min_clicked();
|
||||
void on_btnMenu_Max_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置部件图标
|
||||
void setIcon(QUIWidget::Widget widget, const QChar &str, quint32 size = 12);
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
//设置部件图片
|
||||
void setPixmap(QUIWidget::Widget widget, const QString &file, const QSize &size = QSize(16, 16));
|
||||
//设置部件是否可见
|
||||
void setVisible(QUIWidget::Widget widget, bool visible = true);
|
||||
//设置只有关闭按钮
|
||||
void setOnlyCloseBtn();
|
||||
|
||||
//设置标题栏高度
|
||||
void setTitleHeight(int height);
|
||||
//设置按钮统一宽度
|
||||
void setBtnWidth(int width);
|
||||
|
||||
//设置标题及文本样式
|
||||
void setTitle(const QString &title);
|
||||
void setAlignment(Qt::Alignment alignment);
|
||||
|
||||
//设置最小化隐藏
|
||||
void setMinHide(bool minHide);
|
||||
|
||||
//设置退出时候直接退出整个应用程序
|
||||
void setExitAll(bool exitAll);
|
||||
|
||||
//设置主窗体
|
||||
void setMainWidget(QWidget *mainWidget);
|
||||
|
||||
Q_SIGNALS:
|
||||
void changeStyle(const QString &qssFile);
|
||||
void closing();
|
||||
};
|
||||
|
||||
//弹出信息框类
|
||||
class QUIMessageBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIMessageBox *Instance();
|
||||
explicit QUIMessageBox(QWidget *parent = 0);
|
||||
~QUIMessageBox();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIMessageBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout3;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labTime;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout4;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QFrame *frame;
|
||||
QVBoxLayout *verticalLayout4;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIcoMain;
|
||||
QSpacerItem *horizontalSpacer1;
|
||||
QLabel *labInfo;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QSpacerItem *horizontalSpacer2;
|
||||
QPushButton *btnOk;
|
||||
QPushButton *btnCancel;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setMessage(const QString &msg, int type, int closeSec = 0);
|
||||
};
|
||||
|
||||
//右下角弹出框类
|
||||
class QUITipBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUITipBox *Instance();
|
||||
explicit QUITipBox(QWidget *parent = 0);
|
||||
~QUITipBox();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUITipBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labTime;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QLabel *labInfo;
|
||||
|
||||
QPropertyAnimation *animation;
|
||||
bool fullScreen;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setTip(const QString &title, const QString &tip, bool fullScreen = false, bool center = true, int closeSec = 0);
|
||||
void hide();
|
||||
};
|
||||
|
||||
|
||||
//弹出输入框类
|
||||
class QUIInputBox : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIInputBox *Instance();
|
||||
explicit QUIInputBox(QWidget *parent = 0);
|
||||
~QUIInputBox();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *);
|
||||
void closeEvent(QCloseEvent *);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIInputBox> self;
|
||||
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QLabel *labTime;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout2;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout2;
|
||||
QFrame *frame;
|
||||
QVBoxLayout *verticalLayout3;
|
||||
QLabel *labInfo;
|
||||
QLineEdit *txtValue;
|
||||
QComboBox *cboxValue;
|
||||
QHBoxLayout *lay;
|
||||
QSpacerItem *horizontalSpacer;
|
||||
QPushButton *btnOk;
|
||||
QPushButton *btnCancel;
|
||||
|
||||
private:
|
||||
int closeSec; //总显示时间
|
||||
int currentSec; //当前已显示时间
|
||||
QString value; //当前值
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
void checkSec(); //校验倒计时
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public:
|
||||
QString getValue()const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setParameter(const QString &title, int type = 0, int closeSec = 0,
|
||||
QString placeholderText = QString(), bool pwd = false,
|
||||
const QString &defaultValue = QString());
|
||||
|
||||
};
|
||||
|
||||
//弹出日期选择对话框
|
||||
class QUIDateSelect : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QUIDateSelect *Instance();
|
||||
explicit QUIDateSelect(QWidget *parent = 0);
|
||||
~QUIDateSelect();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<QUIDateSelect> self;
|
||||
|
||||
QVBoxLayout *verticalLayout;
|
||||
QWidget *widgetTitle;
|
||||
QHBoxLayout *horizontalLayout1;
|
||||
QLabel *labIco;
|
||||
QLabel *labTitle;
|
||||
QWidget *widgetMenu;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QPushButton *btnMenu_Close;
|
||||
QWidget *widgetMain;
|
||||
QVBoxLayout *verticalLayout1;
|
||||
QFrame *frame;
|
||||
QGridLayout *gridLayout;
|
||||
QLabel *labStart;
|
||||
QPushButton *btnOk;
|
||||
QLabel *labEnd;
|
||||
QPushButton *btnClose;
|
||||
QDateTimeEdit *dateStart;
|
||||
QDateTimeEdit *dateEnd;
|
||||
|
||||
private:
|
||||
QString startDateTime; //开始时间
|
||||
QString endDateTime; //结束时间
|
||||
QString format; //日期时间格式
|
||||
|
||||
private slots:
|
||||
void initControl(); //初始化控件
|
||||
void initForm(); //初始化窗体
|
||||
|
||||
private slots:
|
||||
void on_btnOk_clicked();
|
||||
void on_btnMenu_Close_clicked();
|
||||
|
||||
public:
|
||||
//获取当前选择的开始时间和结束时间
|
||||
QString getStartDateTime() const;
|
||||
QString getEndDateTime() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setIconMain(const QChar &str, quint32 size = 12);
|
||||
void setFormat(const QString &format);
|
||||
|
||||
};
|
||||
|
||||
//图形字体处理类
|
||||
class IconHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static IconHelper *Instance();
|
||||
explicit IconHelper(QObject *parent = 0);
|
||||
|
||||
//获取图形字体
|
||||
QFont getIconFont();
|
||||
|
||||
//设置图形字体到标签
|
||||
void setIcon(QLabel *lab, const QChar &str, quint32 size = 12);
|
||||
//设置图形字体到按钮
|
||||
void setIcon(QAbstractButton *btn, const QChar &str, quint32 size = 12);
|
||||
|
||||
//获取指定图形字体,可以指定文字大小,图片宽高,文字对齐
|
||||
QPixmap getPixmap(const QColor &color, const QChar &str, quint32 size = 12,
|
||||
quint32 pixWidth = 15, quint32 pixHeight = 15,
|
||||
int flags = Qt::AlignCenter);
|
||||
|
||||
//根据按钮获取该按钮对应的图标
|
||||
QPixmap getPixmap(QToolButton *btn, bool normal);
|
||||
QPixmap getPixmap(QToolButton *btn, int type);
|
||||
|
||||
//指定QFrame导航按钮样式,带图标
|
||||
void setStyle(QFrame *frame, QList<QToolButton *> btns, QList<int> pixChar,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &normalBgColor = "#2FC5A2",
|
||||
const QString &darkBgColor = "#3EA7E9",
|
||||
const QString &normalTextColor = "#EEEEEE",
|
||||
const QString &darkTextColor = "#FFFFFF");
|
||||
|
||||
//指定导航面板样式,不带图标
|
||||
static void setStyle(QWidget *widget, const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
//移除导航面板样式,防止重复
|
||||
void removeStyle(QList<QToolButton *> btns);
|
||||
|
||||
//指定QWidget导航面板样式,带图标和效果切换
|
||||
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> pixChar,
|
||||
quint32 iconSize = 12, quint32 iconWidth = 15, quint32 iconHeight = 15,
|
||||
const QString &type = "left", int borderWidth = 3,
|
||||
const QString &borderColor = "#029FEA",
|
||||
const QString &normalBgColor = "#292F38",
|
||||
const QString &darkBgColor = "#1D2025",
|
||||
const QString &normalTextColor = "#54626F",
|
||||
const QString &darkTextColor = "#FDFDFD");
|
||||
|
||||
struct StyleColor {
|
||||
quint32 iconSize;
|
||||
quint32 iconWidth;
|
||||
quint32 iconHeight;
|
||||
quint32 borderWidth;
|
||||
QString type;
|
||||
QString borderColor;
|
||||
QString normalBgColor;
|
||||
QString normalTextColor;
|
||||
QString hoverBgColor;
|
||||
QString hoverTextColor;
|
||||
QString pressedBgColor;
|
||||
QString pressedTextColor;
|
||||
QString checkedBgColor;
|
||||
QString checkedTextColor;
|
||||
|
||||
StyleColor()
|
||||
{
|
||||
iconSize = 12;
|
||||
iconWidth = 15;
|
||||
iconHeight = 15;
|
||||
borderWidth = 3;
|
||||
type = "left";
|
||||
borderColor = "#029FEA";
|
||||
normalBgColor = "#292F38";
|
||||
normalTextColor = "#54626F";
|
||||
hoverBgColor = "#40444D";
|
||||
hoverTextColor = "#FDFDFD";
|
||||
pressedBgColor = "#404244";
|
||||
pressedTextColor = "#FDFDFD";
|
||||
checkedBgColor = "#44494F";
|
||||
checkedTextColor = "#FDFDFD";
|
||||
}
|
||||
};
|
||||
|
||||
//指定QWidget导航面板样式,带图标和效果切换+悬停颜色+按下颜色+选中颜色
|
||||
void setStyle(QWidget *widget, QList<QToolButton *> btns, QList<int> pixChar, const StyleColor &styleColor);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
static QScopedPointer<IconHelper> self;
|
||||
|
||||
QFont iconFont; //图形字体
|
||||
QList<QToolButton *> btns; //按钮队列
|
||||
QList<QPixmap> pixNormal; //正常图片队列
|
||||
QList<QPixmap> pixDark; //加深图片队列
|
||||
QList<QPixmap> pixHover; //悬停图片队列
|
||||
QList<QPixmap> pixPressed; //按下图片队列
|
||||
QList<QPixmap> pixChecked; //选中图片队列
|
||||
};
|
||||
|
||||
//托盘图标类
|
||||
class TrayIcon : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static TrayIcon *Instance();
|
||||
explicit TrayIcon(QObject *parent = 0);
|
||||
|
||||
private:
|
||||
static QScopedPointer<TrayIcon> self;
|
||||
|
||||
QWidget *mainWidget; //对应所属主窗体
|
||||
QSystemTrayIcon *trayIcon; //托盘对象
|
||||
QMenu *menu; //右键菜单
|
||||
bool exitDirect; //是否直接退出
|
||||
|
||||
private slots:
|
||||
void iconIsActived(QSystemTrayIcon::ActivationReason reason);
|
||||
|
||||
public Q_SLOTS:
|
||||
//设置是否直接退出,如果不是直接退出则发送信号给主界面
|
||||
void setExitDirect(bool exitDirect);
|
||||
|
||||
//设置所属主窗体
|
||||
void setMainWidget(QWidget *mainWidget);
|
||||
|
||||
//显示消息
|
||||
void showMessage(const QString &title, const QString &msg,
|
||||
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int msecs = 5000);
|
||||
|
||||
//设置图标
|
||||
void setIcon(const QString &strIcon);
|
||||
//设置提示信息
|
||||
void setToolTip(const QString &tip);
|
||||
//设置是否可见
|
||||
void setVisible(bool visible);
|
||||
//退出所有
|
||||
void closeAll();
|
||||
|
||||
Q_SIGNALS:
|
||||
void trayIconExit();
|
||||
};
|
||||
|
||||
|
||||
//全局静态方法类
|
||||
class QUIHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
//桌面宽度高度
|
||||
static int deskWidth();
|
||||
static int deskHeight();
|
||||
|
||||
//程序本身文件名称
|
||||
static QString appName();
|
||||
//程序当前所在路径
|
||||
static QString appPath();
|
||||
|
||||
//初始化随机数种子
|
||||
static void initRand();
|
||||
|
||||
//初始化数据库
|
||||
static void initDb(const QString &dbName);
|
||||
//初始化文件,不存在则拷贝
|
||||
static void initFile(const QString &sourceName, const QString &targetName);
|
||||
|
||||
//新建目录
|
||||
static void newDir(const QString &dirName);
|
||||
|
||||
//写入消息到额外的的消息日志文件
|
||||
static void writeInfo(const QString &info, const QString &filePath = "log");
|
||||
static void writeError(const QString &info, const QString &filePath = "log");
|
||||
|
||||
//设置全局样式
|
||||
static void setStyle(QUIWidget::Style style);
|
||||
static void setStyle(const QString &qssFile, QString &paletteColor, QString &textColor);
|
||||
static void setStyle(const QString &qssFile, QString &textColor,
|
||||
QString &panelColor, QString &borderColor,
|
||||
QString &normalColorStart, QString &normalColorEnd,
|
||||
QString &darkColorStart, QString &darkColorEnd,
|
||||
QString &highColor);
|
||||
|
||||
//根据QSS样式获取对应颜色值
|
||||
static void getQssColor(const QString &qss, QString &textColor,
|
||||
QString &panelColor, QString &borderColor,
|
||||
QString &normalColorStart, QString &normalColorEnd,
|
||||
QString &darkColorStart, QString &darkColorEnd,
|
||||
QString &highColor);
|
||||
|
||||
//九宫格图片 horzSplit-宫格1/3/7/9宽度 vertSplit-宫格1/3/7/9高度 dstWidth-目标图片宽度 dstHeight-目标图片高度
|
||||
static QPixmap ninePatch(const QString &picName, int horzSplit, int vertSplit, int dstWidth, int dstHeight);
|
||||
static QPixmap ninePatch(const QPixmap &pix, int horzSplit, int vertSplit, int dstWidth, int dstHeight);
|
||||
|
||||
//设置标签颜色
|
||||
static void setLabStyle(QLabel *lab, quint8 type);
|
||||
|
||||
//设置窗体居中显示
|
||||
static void setFormInCenter(QWidget *frm);
|
||||
//设置翻译文件
|
||||
static void setTranslator(const QString &qmFile = ":/image/qt_zh_CN.qm");
|
||||
//设置编码
|
||||
static void setCode();
|
||||
//设置延时
|
||||
static void sleep(int msec);
|
||||
//设置系统时间
|
||||
static void setSystemDateTime(const QString &year, const QString &month, const QString &day,
|
||||
const QString &hour, const QString &min, const QString &sec);
|
||||
//设置开机自启动
|
||||
static void runWithSystem(const QString &strName, const QString &strPath, bool autoRun = true);
|
||||
|
||||
//判断是否是IP地址
|
||||
static bool isIP(const QString &ip);
|
||||
|
||||
//判断是否是MAC地址
|
||||
static bool isMac(const QString &mac);
|
||||
|
||||
//判断是否是合法的电话号码
|
||||
static bool isTel(const QString &tel);
|
||||
|
||||
//判断是否是合法的邮箱地址
|
||||
static bool isEmail(const QString &email);
|
||||
|
||||
|
||||
//16进制字符串转10进制
|
||||
static int strHexToDecimal(const QString &strHex);
|
||||
|
||||
//10进制字符串转10进制
|
||||
static int strDecimalToDecimal(const QString &strDecimal);
|
||||
|
||||
//2进制字符串转10进制
|
||||
static int strBinToDecimal(const QString &strBin);
|
||||
|
||||
//16进制字符串转2进制字符串
|
||||
static QString strHexToStrBin(const QString &strHex);
|
||||
|
||||
//10进制转2进制字符串一个字节
|
||||
static QString decimalToStrBin1(int decimal);
|
||||
|
||||
//10进制转2进制字符串两个字节
|
||||
static QString decimalToStrBin2(int decimal);
|
||||
|
||||
//10进制转16进制字符串,补零.
|
||||
static QString decimalToStrHex(int decimal);
|
||||
|
||||
|
||||
//int转字节数组
|
||||
static QByteArray intToByte(int i);
|
||||
static QByteArray intToByteRec(int i);
|
||||
|
||||
//字节数组转int
|
||||
static int byteToInt(const QByteArray &data);
|
||||
static int byteToIntRec(const QByteArray &data);
|
||||
static quint32 byteToUInt(const QByteArray &data);
|
||||
static quint32 byteToUIntRec(const QByteArray &data);
|
||||
|
||||
//ushort转字节数组
|
||||
static QByteArray ushortToByte(ushort i);
|
||||
static QByteArray ushortToByteRec(ushort i);
|
||||
|
||||
//字节数组转ushort
|
||||
static int byteToUShort(const QByteArray &data);
|
||||
static int byteToUShortRec(const QByteArray &data);
|
||||
|
||||
//异或加密算法
|
||||
static QString getXorEncryptDecrypt(const QString &str, char key);
|
||||
|
||||
//异或校验
|
||||
static uchar getOrCode(const QByteArray &data);
|
||||
|
||||
//计算校验码
|
||||
static uchar getCheckCode(const QByteArray &data);
|
||||
|
||||
//字符串补全
|
||||
static QString getValue(quint8 value);
|
||||
|
||||
//CRC校验
|
||||
static quint16 getRevCrc_16(quint8 *data, int len, quint16 init, const quint16 *table);
|
||||
static quint16 getCrc_16(quint8 *data, int len, quint16 init, const quint16 *table);
|
||||
static quint16 getModbus16(quint8 *data, int len);
|
||||
static QByteArray getCRCCode(const QByteArray &data);
|
||||
|
||||
|
||||
//字节数组转Ascii字符串
|
||||
static QString byteArrayToAsciiStr(const QByteArray &data);
|
||||
|
||||
//16进制字符串转字节数组
|
||||
static QByteArray hexStrToByteArray(const QString &str);
|
||||
static char convertHexChar(char ch);
|
||||
|
||||
//Ascii字符串转字节数组
|
||||
static QByteArray asciiStrToByteArray(const QString &str);
|
||||
|
||||
//字节数组转16进制字符串
|
||||
static QString byteArrayToHexStr(const QByteArray &data);
|
||||
|
||||
//获取保存的文件
|
||||
static QString getSaveName(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
|
||||
//获取选择的文件
|
||||
static QString getFileName(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
|
||||
//获取选择的文件集合
|
||||
static QStringList getFileNames(const QString &filter, QString defaultDir = QCoreApplication::applicationDirPath());
|
||||
|
||||
//获取选择的目录
|
||||
static QString getFolderName();
|
||||
|
||||
//获取文件名,含拓展名
|
||||
static QString getFileNameWithExtension(const QString &strFilePath);
|
||||
|
||||
//获取选择文件夹中的文件
|
||||
static QStringList getFolderFileNames(const QStringList &filter);
|
||||
|
||||
//文件夹是否存在
|
||||
static bool folderIsExist(const QString &strFolder);
|
||||
|
||||
//文件是否存在
|
||||
static bool fileIsExist(const QString &strFile);
|
||||
|
||||
//复制文件
|
||||
static bool copyFile(const QString &sourceFile, const QString &targetFile);
|
||||
|
||||
//删除文件夹下所有文件
|
||||
static void deleteDirectory(const QString &path);
|
||||
|
||||
//判断IP地址及端口是否在线
|
||||
static bool ipLive(const QString &ip, int port, int timeout = 1000);
|
||||
|
||||
//获取网页所有源代码
|
||||
static QString getHtml(const QString &url);
|
||||
|
||||
//获取本机公网IP地址
|
||||
static QString getNetIP(const QString &webCode);
|
||||
|
||||
//获取本机IP
|
||||
static QString getLocalIP();
|
||||
|
||||
//Url地址转为IP地址
|
||||
static QString urlToIP(const QString &url);
|
||||
|
||||
//判断是否通外网
|
||||
static bool isWebOk();
|
||||
|
||||
|
||||
//弹出消息框
|
||||
static void showMessageBoxInfo(const QString &info, int closeSec = 0, bool exec = false);
|
||||
//弹出错误框
|
||||
static void showMessageBoxError(const QString &info, int closeSec = 0, bool exec = false);
|
||||
//弹出询问框
|
||||
static int showMessageBoxQuestion(const QString &info);
|
||||
|
||||
//弹出+隐藏右下角信息框
|
||||
static void showTipBox(const QString &title, const QString &tip, bool fullScreen = false,
|
||||
bool center = true, int closeSec = 0);
|
||||
static void hideTipBox();
|
||||
|
||||
//弹出输入框
|
||||
static QString showInputBox(const QString &title, int type = 0, int closeSec = 0,
|
||||
const QString &placeholderText = QString(), bool pwd = false,
|
||||
const QString &defaultValue = QString());
|
||||
|
||||
//弹出日期选择框
|
||||
static void showDateSelect(QString &dateStart, QString &dateEnd, const QString &format = "yyyy-MM-dd");
|
||||
|
||||
|
||||
//设置按钮样式
|
||||
static QString setPushButtonQss(QPushButton *btn, //按钮对象
|
||||
int radius = 5, //圆角半径
|
||||
int padding = 8, //间距
|
||||
const QString &normalColor = "#34495E", //正常颜色
|
||||
const QString &normalTextColor = "#FFFFFF", //文字颜色
|
||||
const QString &hoverColor = "#4E6D8C", //悬停颜色
|
||||
const QString &hoverTextColor = "#F0F0F0", //悬停文字颜色
|
||||
const QString &pressedColor = "#2D3E50", //按下颜色
|
||||
const QString &pressedTextColor = "#B8C6D1"); //按下文字颜色
|
||||
|
||||
//设置文本框样式
|
||||
static QString setLineEditQss(QLineEdit *txt, //文本框对象
|
||||
int radius = 3, //圆角半径
|
||||
int borderWidth = 2, //边框大小
|
||||
const QString &normalColor = "#DCE4EC", //正常颜色
|
||||
const QString &focusColor = "#34495E"); //选中颜色
|
||||
|
||||
//设置进度条样式
|
||||
static QString setProgressBarQss(QProgressBar *bar,
|
||||
int barHeight = 8, //进度条高度
|
||||
int barRadius = 5, //进度条半径
|
||||
int fontSize = 9, //文字字号
|
||||
const QString &normalColor = "#E8EDF2", //正常颜色
|
||||
const QString &chunkColor = "#E74C3C"); //进度颜色
|
||||
|
||||
//设置滑块条样式
|
||||
static QString setSliderQss(QSlider *slider, //滑动条对象
|
||||
int sliderHeight = 8, //滑动条高度
|
||||
const QString &normalColor = "#E8EDF2", //正常颜色
|
||||
const QString &grooveColor = "#1ABC9C", //滑块颜色
|
||||
const QString &handleBorderColor = "#1ABC9C", //指示器边框颜色
|
||||
const QString &handleColor = "#FFFFFF", //指示器颜色
|
||||
const QString &textColor = "#000000"); //文字颜色
|
||||
|
||||
//设置单选框样式
|
||||
static QString setRadioButtonQss(QRadioButton *rbtn, //单选框对象
|
||||
int indicatorRadius = 8, //指示器圆角角度
|
||||
const QString &normalColor = "#D7DBDE", //正常颜色
|
||||
const QString &checkColor = "#34495E"); //选中颜色
|
||||
|
||||
//设置滚动条样式
|
||||
static QString setScrollBarQss(QWidget *scroll, //滚动条对象
|
||||
int radius = 6, //圆角角度
|
||||
int min = 120, //指示器最小长度
|
||||
int max = 12, //滚动条最大长度
|
||||
const QString &bgColor = "#606060", //背景色
|
||||
const QString &handleNormalColor = "#34495E", //指示器正常颜色
|
||||
const QString &handleHoverColor = "#1ABC9C", //指示器悬停颜色
|
||||
const QString &handlePressedColor = "#E74C3C"); //指示器按下颜色
|
||||
};
|
||||
|
||||
//全局变量控制
|
||||
class QUIConfig
|
||||
{
|
||||
public:
|
||||
//全局图标
|
||||
static QChar IconMain; //标题栏左上角图标
|
||||
static QChar IconMenu; //下拉菜单图标
|
||||
static QChar IconMin; //最小化图标
|
||||
static QChar IconMax; //最大化图标
|
||||
static QChar IconNormal; //还原图标
|
||||
static QChar IconClose; //关闭图标
|
||||
|
||||
static QString FontName; //全局字体名称
|
||||
static int FontSize; //全局字体大小
|
||||
|
||||
//样式表颜色值
|
||||
static QString TextColor; //文字颜色
|
||||
static QString PanelColor; //面板颜色
|
||||
static QString BorderColor; //边框颜色
|
||||
static QString NormalColorStart;//正常状态开始颜色
|
||||
static QString NormalColorEnd; //正常状态结束颜色
|
||||
static QString DarkColorStart; //加深状态开始颜色
|
||||
static QString DarkColorEnd; //加深状态结束颜色
|
||||
static QString HighColor; //高亮颜色
|
||||
};
|
||||
|
||||
#endif // QUIWIDGET_H
|
|
@ -0,0 +1,163 @@
|
|||
#include "tcpserver.h"
|
||||
#include "quiwidget.h"
|
||||
|
||||
TcpClient::TcpClient(QObject *parent) : QTcpSocket(parent)
|
||||
{
|
||||
ip = "127.0.0.1";
|
||||
port = 6000;
|
||||
|
||||
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(deleteLater()));
|
||||
connect(this, SIGNAL(disconnected()), this, SLOT(deleteLater()));
|
||||
connect(this, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||
}
|
||||
|
||||
void TcpClient::setIP(const QString &ip)
|
||||
{
|
||||
this->ip = ip;
|
||||
}
|
||||
|
||||
QString TcpClient::getIP() const
|
||||
{
|
||||
return this->ip;
|
||||
}
|
||||
|
||||
void TcpClient::setPort(int port)
|
||||
{
|
||||
this->port = port;
|
||||
}
|
||||
|
||||
int TcpClient::getPort() const
|
||||
{
|
||||
return this->port;
|
||||
}
|
||||
|
||||
void TcpClient::readData()
|
||||
{
|
||||
QByteArray data = this->readAll();
|
||||
if (data.length() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString buffer;
|
||||
if (App::HexReceiveTcpServer) {
|
||||
buffer = QUIHelper::byteArrayToHexStr(data);
|
||||
} else if (App::AsciiTcpServer) {
|
||||
buffer = QUIHelper::byteArrayToAsciiStr(data);
|
||||
} else {
|
||||
buffer = QString(data);
|
||||
}
|
||||
|
||||
emit receiveData(ip, port, buffer);
|
||||
|
||||
//自动回复数据,可以回复的数据是以;隔开,每行可以带多个;所以这里不需要继续判断
|
||||
if (App::DebugTcpServer) {
|
||||
int count = App::Keys.count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (App::Keys.at(i) == buffer) {
|
||||
sendData(App::Values.at(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TcpClient::sendData(const QString &data)
|
||||
{
|
||||
QByteArray buffer;
|
||||
if (App::HexSendTcpServer) {
|
||||
buffer = QUIHelper::hexStrToByteArray(data);
|
||||
} else if (App::AsciiTcpServer) {
|
||||
buffer = QUIHelper::asciiStrToByteArray(data);
|
||||
} else {
|
||||
buffer = data.toLatin1();
|
||||
}
|
||||
|
||||
this->write(buffer);
|
||||
emit sendData(ip, port, data);
|
||||
}
|
||||
|
||||
TcpServer::TcpServer(QObject *parent) : QTcpServer(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void TcpServer::incomingConnection(int handle)
|
||||
{
|
||||
TcpClient *client = new TcpClient(this);
|
||||
client->setSocketDescriptor(handle);
|
||||
connect(client, SIGNAL(disconnected()), this, SLOT(disconnected()));
|
||||
connect(client, SIGNAL(sendData(QString, int, QString)), this, SIGNAL(sendData(QString, int, QString)));
|
||||
connect(client, SIGNAL(receiveData(QString, int, QString)), this, SIGNAL(receiveData(QString, int, QString)));
|
||||
|
||||
QString ip = client->peerAddress().toString();
|
||||
int port = client->peerPort();
|
||||
client->setIP(ip);
|
||||
client->setPort(port);
|
||||
emit clientConnected(ip, port);
|
||||
emit sendData(ip, port, "客户端上线");
|
||||
|
||||
//连接后加入链表
|
||||
clients.append(client);
|
||||
}
|
||||
|
||||
void TcpServer::disconnected()
|
||||
{
|
||||
TcpClient *client = (TcpClient *)sender();
|
||||
QString ip = client->getIP();
|
||||
int port = client->getPort();
|
||||
emit clientDisconnected(ip, port);
|
||||
emit sendData(ip, port, "客户端下线");
|
||||
|
||||
//断开连接后从链表中移除
|
||||
clients.removeOne(client);
|
||||
}
|
||||
|
||||
bool TcpServer::start()
|
||||
{
|
||||
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
|
||||
bool ok = listen(QHostAddress::AnyIPv4, App::TcpListenPort);
|
||||
#else
|
||||
bool ok = listen(QHostAddress::Any, App::TcpListenPort);
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
void TcpServer::stop()
|
||||
{
|
||||
remove();
|
||||
this->close();
|
||||
}
|
||||
|
||||
void TcpServer::writeData(const QString &ip, int port, const QString &data)
|
||||
{
|
||||
foreach (TcpClient *client, clients) {
|
||||
if (client->peerAddress().toString() == ip && client->peerPort() == port) {
|
||||
client->sendData(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TcpServer::writeData(const QString &data)
|
||||
{
|
||||
foreach (TcpClient *client, clients) {
|
||||
client->sendData(data);
|
||||
}
|
||||
}
|
||||
|
||||
void TcpServer::remove(const QString &ip, int port)
|
||||
{
|
||||
foreach (TcpClient *client, clients) {
|
||||
if (client->peerAddress().toString() == ip && client->peerPort() == port) {
|
||||
client->disconnectFromHost();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TcpServer::remove()
|
||||
{
|
||||
foreach (TcpClient *client, clients) {
|
||||
client->disconnectFromHost();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
#ifndef TCPSERVER_H
|
||||
#define TCPSERVER_H
|
||||
|
||||
#include <QtNetwork>
|
||||
|
||||
class TcpClient : public QTcpSocket
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TcpClient(QObject *parent = 0);
|
||||
|
||||
private:
|
||||
QString ip;
|
||||
int port;
|
||||
|
||||
public:
|
||||
void setIP(const QString &ip);
|
||||
QString getIP()const;
|
||||
|
||||
void setPort(int port);
|
||||
int getPort()const;
|
||||
|
||||
private slots:
|
||||
void readData();
|
||||
|
||||
signals:
|
||||
void sendData(const QString &ip, int port, const QString &data);
|
||||
void receiveData(const QString &ip, int port, const QString &data);
|
||||
|
||||
public slots:
|
||||
void sendData(const QString &data);
|
||||
|
||||
};
|
||||
|
||||
class TcpServer : public QTcpServer
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit TcpServer(QObject *parent = 0);
|
||||
|
||||
private:
|
||||
QList<TcpClient *> clients;
|
||||
|
||||
protected:
|
||||
void incomingConnection(int handle);
|
||||
|
||||
private slots:
|
||||
void disconnected();
|
||||
|
||||
signals:
|
||||
void sendData(const QString &ip, int port, const QString &data);
|
||||
void receiveData(const QString &ip, int port, const QString &data);
|
||||
|
||||
void clientConnected(const QString &ip, int port);
|
||||
void clientDisconnected(const QString &ip, int port);
|
||||
|
||||
public slots:
|
||||
//启动服务
|
||||
bool start();
|
||||
//停止服务
|
||||
void stop();
|
||||
|
||||
//指定连接发送数据
|
||||
void writeData(const QString &ip, int port, const QString &data);
|
||||
//对所有连接发送数据
|
||||
void writeData(const QString &data);
|
||||
|
||||
//断开指定连接
|
||||
void remove(const QString &ip, int port);
|
||||
//断开所有连接
|
||||
void remove();
|
||||
|
||||
};
|
||||
|
||||
#endif // TCPSERVER_H
|
|
@ -0,0 +1,20 @@
|
|||
2015;\NUL2015
|
||||
666;667
|
||||
3001P;301PST1:hehe'2:P2'3:P3'
|
||||
3002P;301PST
|
||||
3003P;301PST
|
||||
3004P;301PST
|
||||
3005P;301PST
|
||||
326;00110
|
||||
320;00101
|
||||
330010;00101
|
||||
331;332001
|
||||
568X;5691:0
|
||||
5700;5710:10:1;2;3
|
||||
330051;00101
|
||||
112P001000I1';113P001100I1'101I1'102B0'103B0'106B0'107I0'108I1'109I0'110R1.750000'111R6.300000'112R1.500000'113R3.100000'114R4.500000'115R1.050000'116R7.000000'117R9999.000000'118I0'119R3.500000'120R1.750000'121I1'122I0'123I0'124I70'130I1000'131I8000'132I1500'133I10000'134I10'135I5'136I20'137I40'140R0.000000'105B1'138I700'104I0'125I0'126I9999'141R0.200000'142R0.200000'143R0.000000'144R30.000000'150I1'151I10'152B0'153I0'160I0'200B0'210B0'211I1'212I1'213R1.050000'214R9999.000000'220B0'221I0'222I1'223I1'224R1.050000'225R7.000000'230B0'240I0'241B1'242B0'243B0'244B0'245R100.000000'246B0'260R0.000000'261I0'262I0'263I50'264I0'280B0'281R1.050000'282I9999'283I1'284R7.000000'285I1'286I1'290I0'291R9999.000000'292R9999.000000'293I10'294I150'295I0'402Shehe'406I1433082933'500R0.000000'501R9999.000000'502I4'503I10'504I1'505I30'506B0'510R0.000000'511R9999.000000'512R0.000000'513R9999.000000'514R0.000000'515R0.000000'507B0'520I0'521I9999'522I0'523I9999'524I0'525I0'508B0'560R0.000000'561R9999.000000'562R0.000000'563R9999.000000'564R0.000000'565R0.000000'530I0'531I9999'532I0'533I9999'534I0'535I0'540R0.000000'541R9999.000000'542R0.000000'543R9999.000000'544R0.000000'545R0.000000'550R0.000000'551R9999.000000'552R0.000000'553R9999.000000'554R0.000000'555R0.000000'
|
||||
302P001;00101
|
||||
002;003\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL
|
||||
112R000;113R001100R2.530000'101I1'102I23'103I1'104I0'105I0'106I3'107B1'108I0'109I2'110R0.000000'111I1'116R0.000000'117R0.000000'118I1'120I0'121I1'122R0.000000'123I1'300I186'301S2015-06-01'302S15:53:56'303S'305S359194'311I0'312I0'313I0'314I1'319I0'340I1'341I0'351SGUT'360S'361S'362S'
|
||||
126;123G100I00186'101S2015-06-01'102S15:53:56'103S'104S0'105S359194'106I00000'107I00000'110I00000'111I00000'112I00000'113I00000'114I00001'115I00000'116I00000'200I00003'201R00001.50'202I00000'203I01060'204I1638400'205I00001'206R00002.50'210R00002.20'211R00002.80'212R00000.00'213R00000.00'214R00000.42'215R09999.00'216R00000.42'217R00002.80'218R00000.00'219R00000.00'230R00000.42'231R00002.80'232R00002.53';\ETX\xA6\EOT]\ENQI\ACK{\x08\ETX\x07\xB0\ENQ\xEA\NUL\xD8\xFF\x9F\xFF\x7F\xFF\xC3\xFF\xFC\xFF\x10\xFF\xC1\NUL\EOT\xFF\xFC\NUL\CR\SOH\CR\SOH\xB4\SOH\xC2\SOH\xC8\SOH\xC8\SOH\xA6\SOH\x94\SOH\xA8\SOH\xC6\SOH\xD8\SOH\xDC\SOH\xDA\SOH\xD8\SOH\xDA\SOH\xDA\SOH\xDC\SOH\xDC\SOH\xE4\SOH\xEC\SOH\xF4\STX\NUL\STX\LF\STX\x12\STX\x12\STX\x16\STX\x14\STX\x10\STX\x08\SOH\xE8\SOH\x98\SOH-\NUL\xE1\NUL\xA2\NUL\x86\NUL\x86\NUL\x96\NUL\xA8\NUL\xBF\NUL\xDD\NUL\xFF\SOH\x1D\SOH?\SOH_\SOHz\SOH\x98\SOH\xB4\SOH\xCC\SOH\xE4\SOH\xFA\STX\NUL\STX\ACK\STX\x08\STX\x0C\STX\ACK\STX\STX\SOH\xFE\SOH\xF6\SOH\xF4\SOH\xF6\SOH\xFA\STX\STX\STX\x0E\STX\x16\STX\x19\STX\x19\STX\ESC\STX\x1F\STX\x1F\STX\ESC\STX\x14\STX\x12\STX\x16\STX\ESC\STX%\STX3\STXA\STXC\STXG\STXM\STXO\STXO\STXO\STXO\STXO\STXU\STXU\STX]\STXe\STXq\STXw\STXy\STX\x7F\STX\x7F\STX\x81\STX\x85\STX\x83\STX\x83\STX\x87\STX\x8B\STX\x95\STX\xA7\STX\xBB\STX\xCE\STX\xD8\STX\xE6\STX\xF8\ETX\x10\ETX$\ETX:\ETXP\ETXn\ETX\x8F\ETX\xB3\ETX\xDD\EOT\x07\EOT+\EOTN\EOTh\EOT\x84\EOT\xA0\EOT\xBA\EOT\xD4\EOT\xE7\EOT\xF9\ENQ\x0F\ENQ)\ENQG\ENQi\ENQ\x95\ENQ\xB4\ENQ\xD0\ENQ\xEC\ACK\x0C\ACK(\ACKF\ACK[\ACKm\ACK}\ACK\x93\ACK\xA3\ACK\xBD\ACK\xDD\x07\STX\x07"\x07D\x07h\x07\x86\x07\x9E\x07\xB7\x07\xC7\x07\xD5\x07\xE5\x07\xFB\x08\ESC\x08C\x08p\x08\x8E\x08\xA6\x08\xB8\x08\xC2\x08\xCC\x08\xDA\x08\xE6\x08\xF4\x09\ACK\x09\x19\x09-\x09G\x09c\x09y\x09\x8B\x09\xA3\x09\xB9\x09\xC8\x09\xDA\x09\xE8\x09\xF8\LF\x10\LF(\LFB\LF^\LF\x81\LF\x9D\LF\xB3\LF\xCB\LF\xE5\LF\xFD\x0B\x13\x0B,\x0B>\x0BX\x0Br\x0B\x90\x0B\xAE\x0B\xCC\x0B\xED\x0C\x09\x0C%\x0CE\x0Ce\x0C}\x0C\x92\x0C\xA8\x0C\xBC\x0C\xD4\x0C\xEE\CR\x0C\CR,\CRO\CRk\CR\x87\CR\xA3\CR\xBD\CR\xD5\CR\xF0\x0E\ACK\x0E\x1C\x0E4\x0ER\x0En\x0E\x90\x0E\xB9\x0E\xDF\x0E\xFF\x0F\x1D\x0F?\x0F%\x0E\xB6\CR\xC3\x0C\x1F\LF:\x08e\ACK\xD3\ENQ\xA3\ENQ\x11\ENQE\ACK$\x07`\x08\x8F\x09}\LF\x12\LFV\LFb\LFH\LF\x16\x09\xDA\x09\x9D\x09k\x09C\x09\x16\x08\xF0\x08\xD8\x08\xC4\x08\xB4\x08\xAE\x08\xAE\x08\xB4\x08\xC0\x08\xC4\x08\xC2\x08\xB2\x08\xA4\x08\x94\x08x\x08Q\x08)\x07\xFB\x07\xD1\x07\xB3\x07\x98\x07\x82\x07h\x07N\x07B\x07B\x07D\x07@\x074\x07$\x07\x12\ACK\xF9\ACK\xDD\ACK\xBF\ACK\xA5\ACK\x93\ACK\x87\ACKy\ACKi\ACK[\ACKM\ACK:\ACK$\ACK\x08\ENQ\xE4\ENQ\xCC\ENQ\xB6\ENQ\xA0\ENQ\x83\ENQk\ENQY\ENQM\ENQM\ENQM\ENQK\ENQE\ENQA\ENQ?\ENQ5\ENQ%\ENQ\x11\ENQ\SOH\EOT\xF7\EOT\xEB\EOT\xE7\EOT\xE7\EOT\xED\EOT\xED\EOT\xEB\EOT\xE3\EOT\xD6\EOT\xCE\EOT\xCE\EOT\xC8\EOT\xBE\EOT\xB4\EOT\xAC\EOT\xA4\EOT\xAA\EOT\xA8\EOT\x9E\EOT\x94\EOT\x8C\EOT\x80\EOTn\EOTT\EOT8\EOT\x17\ETX\xFF\ETX\xE9\ETX\xD1\ETX\xC5\ETX\xB5\ETX\xA7\ETX\x8F\ETXx\ETX\\\ETX>\ETX$\ETX\x0E\STX\xE8\STX\xC5\STX\xA5\STX\x91\STX\x7F\STXm\STX]\STXG\STX-\STX\x1D\STX\x0C\SOH\xFA\SOH\xF0\SOH\xDE\SOH\xD0\SOH\xBE\SOH\xB2\SOH\xA4\SOH\x9A\SOH\x88\SOH~\SOHp\SOH]\SOHE\SOH3\SOH%\SOH\x17\SOH\ETX\NUL\xDF\NUL\xB0\NUL\x84\NULj\NULT\NUL>\NUL*\NUL\CAN\NUL\x0C\xFF\xFE\xFF\xF1\xFF\xE9\xFF\xE1\xFF\xE1\xFF\xE1\xFF\xE1\xFF\xE3\xFF\xEB\xFF\xEF\xFF\xF3\xFF\xF5\xFF\xF7\xFF\xF3\xFF\xF1\xFF\xEB\xFF\xE7\xFF\xE7\xFF\xE7\xFF\xE7\xFF\xE9\xFF\xEF\xFF\xF7\xFF\xF9\xFF\xFE\NUL\NUL\NUL\NUL\xFF\xFE\xFF\xF7\xFF\xF3\xFF\xED\xFF\xED\xFF\xED\xFF\xF3\xFF\xFC\NUL\EOT\NUL\x0C\NUL\x0E\NUL\x12\NUL\x12\NUL\x10\NUL\x08\NUL\STX\xFF\xFE\xFF\xF9\xFF\xF9\xFF\xF9\NUL\NUL\NUL\ACK\NUL\x0C\NUL\x12\NUL\x12\NUL\x10\NUL\LF\NUL\STX\xFF\xF9\xFF\xF3\xFF\xF3\xFF\xED\xFF\xED\xFF\xF1\xFF\xF7\xFF\xFE\NUL\EOT\NUL\ACK\NUL\ACK\NUL\EOT\xFF\xFA\xFF\xF3\xFF\xF3\xFF\xF3\xFF\xF3\xFF\xF3\xFF\xF3\xFF\xF9\xFF\xFC\xFF\xF9\xFF\xF9\xFF\xF9\xFF\xFE\xFF\xF9\xFF\xF5\xFF\xEF\xFF\xE9\xFF\xE5\xFF\xE1\xFF\xE1\xFF\xE9\xFF\xED\xFF\xF5\xFF\xF9\xFF\xF9\NUL\NUL\xFF\xFE\xFF\xF9\xFF\xF3\xFF\xF3\xFF\xF3\xFF\xEF\xFF\xF3\xFF\xF5\xFF\xFE\NUL\EOT\NUL\ACK\NUL\ACK\NUL\ACK\NUL\ACK\NUL\ACK\NUL\NUL\xFF\xF9\xFF\xF3
|
||||
127;125G100I00186'101S2015-06-01'102S15:53:56'103S'104S0'105S359194'106I00000'107I00000'110I00000'111I00000'112I00000'113I00000'114I00001'115I00000'116I00000'200I00003'201R00001.50'202I00000'203I36000'204I01979'205I08192'220I00002'221I09000'222I00000'223I09999'224I00771'225I00000'226I00001'227I00000'228I00001'229I00023'240I-9997'241I00001'242I00001'243I00001'244I00000'245I09998';\NUL\NUL\x08%\CR4\x111\NAK\xA6\CAN\ETX\x16\xD6\x14\CR\x0F\xBA\x0C\x12\x07\x85\EOT\xCB\ETX]\ETX\x80\EOT\x9E\ENQ\xE4\x07\x8B\x08\xCB\LFA\x0BM\x0Cq\CR:\x0E\x16\x0E\xAB\x0FM\x0F\xC1\x10>\x10\x93\x10\xF3\x115\x11}\x11\xAE\x11\xE3\x12\x08\x120\x12N\x12n\x12\x81\x12\x96\x12\xA4\x12\xB5\x12\xC1\x12\xCD\x12\xD4\x12\xD8\x12\xCA\x12\xA3\x12\x82\x12^\x12E\x12/\x12$\x12\x1A\x12\x13\x12\CR\x12\ACK\x11\xFF\x11\xF9\x11\xF0\x11\xE8\x11\xDE\x11\xDA\x11\xCF\x11\xC7\x11\xBC\x11\xB2\x11\xA8\x11\xA4\x11\x9E\x11\x9C\x11\x9C\x11\x9C\x11\x9D\x11\x9F\x11\x9F\x11\x9F\x11\xA0\x11\xA3\x11\xA7\x11\xA9\x11\xA9\x11\xAB\x11\xB2\x11\xBA\x11\xC3\x11\xCC\x11\xD7\x11\xE0\x11\xEB\x11\xF6\x12\ACK\x12\x11\x12"\x12/\x12@\x12M\x12b\x12r\x12\x86\x12\x9A\x12\xB3\x12\xC9\x12\xDD\x12\xF1\x13\x08\x13\x1C\x134\x13I\x13d\x13|\x13\x99\x13\xB3\x13\xD2\x13\xEC\x14\CR\x14%\x14F\x14_\x14\x7F\x14\x9A\x14\xBC\x14\xD9\x14\xFB\NAK\NAK\NAK7\NAKS\NAKw\NAK\x91\NAK\xB1\NAK\xC9\NAK\xE3\NAK\xF7\x16\x0F\x16"\x168\x16K\x16d\x16v\x16\x8D\x16\x9E\x16\xB2\x16\xC5\x16\xDE\x16\xF4\x17\x0E\x17"\x17>\x17T\x17u\x17\x91\x17\xB3\x17\xCF\x17\xEF\CAN\LF\CAN*\CAND\CANd\CAN\x7F\CAN\xA4\CAN\xC4\CAN\xEE\x19\x0F\x199\x19[\x19\x82\x19\xA3\x19\xC5\x19\xE1\x1A\ENQ\x1A#\x1AI\x1Al\x1A\x98\x1A\xBC\x1A\xE8\ESC\x0E\ESC>\ESCg\ESC\x9D\ESC\xCC\x1C\x08\x1C:\x1Cw\x1C\xAA\x1C\xE7\x1D\x17\x1DP\x1D~\x1D\xB8\x1D\xE8\x1E"\x1EO\x1E\x89\x1E\xBA\x1E\xF7\x1F(\x1Fj\x1F\xA1\x1F\xE2 \NAK Q \x82 \xBD \xEE!-!a!\xA5!\xDD"$"^"\xA7"\xDE###W#\x98#\xD0$\x1C$Y$\xA5$\xE4%4%v%\xC9&\x07&S&\x8F&\xD6'\x13'a'\x9F'\xEB(((y(\xBD)\x13)W)\xB0)\xF3*J*\x90*\xE4+-+\x81+\xAD+\xA5+}+\x1C*\xBF*:)\xD0)\\)!)\x11)\x1F)6)>)9)))\x0E(\xF7(\xD5(\xBE(\x9F(\x8B(t(c(P(?(,(\x1D(\x0B'\xFD'\xEC'\xDF'\xCE'\xC1'\xAE'\x9E'\x8B'|'j'Y'F'8'%'\x19'\LF&\xFF&\xEB&\xDC&\xCC&\xC1&\xB1&\xA5&\x94&\x88&w&j&Y&L&>&4&&&\x1C&\CR&\STX%\xF7%\xEE%\xDF%\xD1%\xC1%\xB7%\xAA%\x9E%\x89%{%j%]%O%C%6%+%\x1E%\x11%\NUL$\xF0$\xD8$\xC8$\xB2$\x9D$\x85$p$X$E$($\x0F#\xF1#\xDB#\xC0#\xA7#\x85#j#M#4#\x12"\xF6"\xD5"\xBA"\x9A"}"W":"\x12!\xF5!\xD0!\xB4!\x8F!r!Q!8!\x1A!\SOH \xE4 \xCC \xB3 \x9B } g L 6 \x1C \ENQ\x1F\xEA\x1F\xD3\x1F\xBA\x1F\xA5\x1F\x8B\x1Fv\x1F[\x1FF\x1F(\x1F\x13\x1E\xF4\x1E\xDB\x1E\xBF\x1E\xA9\x1E\x8F\x1Ew\x1E[\x1EB\x1E(\x1E\x12\x1D\xFB\x1D\xE5\x1D\xC4\x1D\xA5\x1Dz\x1DU\x1D(\x1D\x07\x1C\xDB\x1C\xBB\x1C\x95\x1Cx\x1CZ\x1CD\x1C*\x1C\x1C\x1C\LF\ESC\xFE\ESC\xF4\ESC\xEE\ESC\xEA\ESC\xE5\ESC\xE7\ESC\xE7\ESC\xE8\ESC\xEB\ESC\xF0\ESC\xF3\ESC\xF8\ESC\xFF\x1C\x08\x1C\x0B\x1C\x16\x1C\ESC\x1C#\x1C(\x1C/\x1C5\x1C<\x1C@\x1CH\x1CN\x1CT\x1CZ\x1Cb\x1Ce\x1Ck\x1Cp\x1Cv\x1Cy\x1C{\x1C{\x1Cx\x1Cv\x1Cr\x1Cq\x1Cp\x1Co\x1Co\x1Co\x1Co\x1Cp\x1Cq\x1Cq\x1Cq\x1Cq\x1Ct\x1Ct\x1Ct\x1Cv\x1Cs\x1Cu\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cv\x1Cw\x1Cx\x1Cz\x1Cz\x1C{\x1C{\x1C{\x1C{\x1C{\x1C}\x1C\x7F\x1C}\x1C~\x1C}\x1C}\x1C\x7F\x1C}\x1C}\x1C|\x1C{\x1C{\x1C{\x1C{\x1C{\x1C{\x1C{\x1C{\x1C{\x1C{\x1C{\x1C{\x1C{
|
|
@ -0,0 +1,17 @@
|
|||
16 FF 01 01 E0 E1
|
||||
16 FF 01 01 E1 E2
|
||||
16 01 02 DF BC 16 01 02 DF BC 16 01 02 DF BC 12 13 14 15
|
||||
16 00 00 04 D0 F0 F1 65 C4
|
||||
16 00 00 04 D0 05 AB 5A C4
|
||||
16 01 10 02 F0 03 06 16 01 11 02 F0 03 06 16 01 12 02 F0 03 06 16 01 13 02 F0 03 06 16 01
|
||||
14 02 F0 03 06 16 01 15 02 F0 03 06 16 01 16 02 F0 03 06
|
||||
16 11 01 03 E8 01 10 0E
|
||||
16 11 01 03 E8 01 12 10
|
||||
16 11 01 03 E8 01 14 12
|
||||
16 11 01 03 E8 01 15 13
|
||||
DISARMEDALL
|
||||
BURGLARY 012
|
||||
BYPASS 012
|
||||
DISARMED 012
|
||||
16 00 01 01 D1 D3
|
||||
16 01 11 11
|
|
@ -0,0 +1,17 @@
|
|||
FORMS += \
|
||||
$$PWD/frmmain.ui \
|
||||
$$PWD/frmtcpclient.ui \
|
||||
$$PWD/frmtcpserver.ui \
|
||||
$$PWD/frmudpserver.ui
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/frmmain.h \
|
||||
$$PWD/frmtcpclient.h \
|
||||
$$PWD/frmtcpserver.h \
|
||||
$$PWD/frmudpserver.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/frmmain.cpp \
|
||||
$$PWD/frmtcpclient.cpp \
|
||||
$$PWD/frmtcpserver.cpp \
|
||||
$$PWD/frmudpserver.cpp
|
|
@ -0,0 +1,20 @@
|
|||
#include "frmmain.h"
|
||||
#include "ui_frmmain.h"
|
||||
#include "quiwidget.h"
|
||||
|
||||
frmMain::frmMain(QWidget *parent) : QWidget(parent), ui(new Ui::frmMain)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->tabWidget->setCurrentIndex(App::CurrentIndex);
|
||||
}
|
||||
|
||||
frmMain::~frmMain()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void frmMain::on_tabWidget_currentChanged(int index)
|
||||
{
|
||||
App::CurrentIndex = index;
|
||||
App::writeConfig();
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef FRMMAIN_H
|
||||
#define FRMMAIN_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class frmMain;
|
||||
}
|
||||
|
||||
class frmMain : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit frmMain(QWidget *parent = 0);
|
||||
~frmMain();
|
||||
|
||||
private slots:
|
||||
void on_tabWidget_currentChanged(int index);
|
||||
|
||||
private:
|
||||
Ui::frmMain *ui;
|
||||
};
|
||||
|
||||
#endif // FRMMAIN_H
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>frmMain</class>
|
||||
<widget class="QWidget" name="frmMain">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="tabPosition">
|
||||
<enum>QTabWidget::South</enum>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<widget class="frmTcpClient" name="tabTcpClient">
|
||||
<attribute name="title">
|
||||
<string>TCP客户端</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="frmTcpServer" name="tabTcpServer">
|
||||
<attribute name="title">
|
||||
<string>TCP服务器</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="frmUdpServer" name="tabUdpServer">
|
||||
<attribute name="title">
|
||||
<string>UDP服务器</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>frmTcpClient</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>frmtcpclient.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>frmTcpServer</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>frmtcpserver.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>frmUdpServer</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>frmudpserver.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,223 @@
|
|||
#include "frmtcpclient.h"
|
||||
#include "ui_frmtcpclient.h"
|
||||
#include "quiwidget.h"
|
||||
|
||||
frmTcpClient::frmTcpClient(QWidget *parent) : QWidget(parent), ui(new Ui::frmTcpClient)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->initForm();
|
||||
this->initConfig();
|
||||
}
|
||||
|
||||
frmTcpClient::~frmTcpClient()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void frmTcpClient::initForm()
|
||||
{
|
||||
isOk = false;
|
||||
tcpSocket = new QTcpSocket(this);
|
||||
connect(tcpSocket, SIGNAL(connected()), this, SLOT(connected()));
|
||||
connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(disconnected()));
|
||||
connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
|
||||
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
|
||||
|
||||
ui->cboxInterval->addItems(App::Intervals);
|
||||
ui->cboxData->addItems(App::Datas);
|
||||
}
|
||||
|
||||
void frmTcpClient::initConfig()
|
||||
{
|
||||
ui->ckHexSend->setChecked(App::HexSendTcpClient);
|
||||
connect(ui->ckHexSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckHexReceive->setChecked(App::HexReceiveTcpClient);
|
||||
connect(ui->ckHexReceive, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckAscii->setChecked(App::AsciiTcpClient);
|
||||
connect(ui->ckAscii, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckDebug->setChecked(App::DebugTcpClient);
|
||||
connect(ui->ckDebug, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckAutoSend->setChecked(App::AutoSendTcpClient);
|
||||
connect(ui->ckAutoSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(App::IntervalTcpClient)));
|
||||
connect(ui->cboxInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtServerIP->setText(App::TcpServerIP);
|
||||
connect(ui->txtServerIP, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtServerPort->setText(QString::number(App::TcpServerPort));
|
||||
connect(ui->txtServerPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
timer->setInterval(App::IntervalTcpClient);
|
||||
App::AutoSendTcpClient ? timer->start() : timer->stop();
|
||||
}
|
||||
|
||||
void frmTcpClient::saveConfig()
|
||||
{
|
||||
App::HexSendTcpClient = ui->ckHexSend->isChecked();
|
||||
App::HexReceiveTcpClient = ui->ckHexReceive->isChecked();
|
||||
App::AsciiTcpClient = ui->ckAscii->isChecked();
|
||||
App::DebugTcpClient = ui->ckDebug->isChecked();
|
||||
App::AutoSendTcpClient = ui->ckAutoSend->isChecked();
|
||||
App::IntervalTcpClient = ui->cboxInterval->currentText().toInt();
|
||||
App::TcpServerIP = ui->txtServerIP->text().trimmed();
|
||||
App::TcpServerPort = ui->txtServerPort->text().trimmed().toInt();
|
||||
App::writeConfig();
|
||||
|
||||
timer->setInterval(App::IntervalTcpClient);
|
||||
App::AutoSendTcpClient ? timer->start() : timer->stop();
|
||||
}
|
||||
|
||||
void frmTcpClient::append(int type, const QString &data, bool clear)
|
||||
{
|
||||
static int currentCount = 0;
|
||||
static int maxCount = 100;
|
||||
|
||||
if (clear) {
|
||||
ui->txtMain->clear();
|
||||
currentCount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentCount >= maxCount) {
|
||||
ui->txtMain->clear();
|
||||
currentCount = 0;
|
||||
}
|
||||
|
||||
if (ui->ckShow->isChecked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//过滤回车换行符
|
||||
QString strData = data;
|
||||
strData = strData.replace("\r", "");
|
||||
strData = strData.replace("\n", "");
|
||||
|
||||
//不同类型不同颜色显示
|
||||
QString strType;
|
||||
if (type == 0) {
|
||||
strType = "发送";
|
||||
ui->txtMain->setTextColor(QColor("darkgreen"));
|
||||
} else {
|
||||
strType = "接收";
|
||||
ui->txtMain->setTextColor(QColor("red"));
|
||||
}
|
||||
|
||||
strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData);
|
||||
ui->txtMain->append(strData);
|
||||
currentCount++;
|
||||
}
|
||||
|
||||
void frmTcpClient::connected()
|
||||
{
|
||||
isOk = true;
|
||||
ui->btnConnect->setText("断开");
|
||||
append(0, "服务器连接");
|
||||
}
|
||||
|
||||
void frmTcpClient::disconnected()
|
||||
{
|
||||
isOk = false;
|
||||
tcpSocket->abort();
|
||||
ui->btnConnect->setText("连接");
|
||||
append(1, "服务器断开");
|
||||
}
|
||||
|
||||
void frmTcpClient::readData()
|
||||
{
|
||||
QByteArray data = tcpSocket->readAll();
|
||||
if (data.length() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString buffer;
|
||||
if (App::HexReceiveTcpClient) {
|
||||
buffer = QUIHelper::byteArrayToHexStr(data);
|
||||
} else if (App::AsciiTcpClient) {
|
||||
buffer = QUIHelper::byteArrayToAsciiStr(data);
|
||||
} else {
|
||||
buffer = QString(data);
|
||||
}
|
||||
|
||||
append(1, buffer);
|
||||
|
||||
//自动回复数据,可以回复的数据是以;隔开,每行可以带多个;所以这里不需要继续判断
|
||||
if (App::DebugTcpClient) {
|
||||
int count = App::Keys.count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (App::Keys.at(i) == buffer) {
|
||||
sendData(App::Values.at(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void frmTcpClient::sendData(const QString &data)
|
||||
{
|
||||
QByteArray buffer;
|
||||
if (App::HexSendTcpClient) {
|
||||
buffer = QUIHelper::hexStrToByteArray(data);
|
||||
} else if (App::AsciiTcpClient) {
|
||||
buffer = QUIHelper::asciiStrToByteArray(data);
|
||||
} else {
|
||||
buffer = data.toLatin1();
|
||||
}
|
||||
|
||||
tcpSocket->write(buffer);
|
||||
append(0, data);
|
||||
}
|
||||
|
||||
void frmTcpClient::on_btnConnect_clicked()
|
||||
{
|
||||
if (ui->btnConnect->text() == "连接") {
|
||||
tcpSocket->abort();
|
||||
tcpSocket->connectToHost(App::TcpServerIP, App::TcpServerPort);
|
||||
} else {
|
||||
tcpSocket->abort();
|
||||
}
|
||||
}
|
||||
|
||||
void frmTcpClient::on_btnSave_clicked()
|
||||
{
|
||||
QString data = ui->txtMain->toPlainText();
|
||||
if (data.length() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString fileName = QString("%1/%2.txt").arg(QUIHelper::appPath()).arg(STRDATETIME);
|
||||
QFile file(fileName);
|
||||
if (file.open(QFile::WriteOnly | QFile::Text)) {
|
||||
file.write(data.toUtf8());
|
||||
file.close();
|
||||
}
|
||||
|
||||
on_btnClear_clicked();
|
||||
}
|
||||
|
||||
void frmTcpClient::on_btnClear_clicked()
|
||||
{
|
||||
append(0, "", true);
|
||||
}
|
||||
|
||||
void frmTcpClient::on_btnSend_clicked()
|
||||
{
|
||||
if (!isOk) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString data = ui->cboxData->currentText();
|
||||
if (data.length() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendData(data);
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
#ifndef FRMTCPCLIENT_H
|
||||
#define FRMTCPCLIENT_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QtNetwork>
|
||||
|
||||
namespace Ui {
|
||||
class frmTcpClient;
|
||||
}
|
||||
|
||||
class frmTcpClient : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit frmTcpClient(QWidget *parent = 0);
|
||||
~frmTcpClient();
|
||||
|
||||
private:
|
||||
Ui::frmTcpClient *ui;
|
||||
|
||||
bool isOk;
|
||||
QTcpSocket *tcpSocket;
|
||||
QTimer *timer;
|
||||
|
||||
private slots:
|
||||
void initForm();
|
||||
void initConfig();
|
||||
void saveConfig();
|
||||
void append(int type, const QString &data, bool clear = false);
|
||||
|
||||
void connected();
|
||||
void disconnected();
|
||||
void readData();
|
||||
void sendData(const QString &data);
|
||||
|
||||
private slots:
|
||||
void on_btnConnect_clicked();
|
||||
void on_btnSave_clicked();
|
||||
void on_btnClear_clicked();
|
||||
void on_btnSend_clicked();
|
||||
};
|
||||
|
||||
#endif // FRMTCPCLIENT_H
|
|
@ -0,0 +1,213 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>frmTcpClient</class>
|
||||
<widget class="QWidget" name="frmTcpClient">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTextEdit" name="txtMain">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="2">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<property name="leftMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckHexReceive">
|
||||
<property name="text">
|
||||
<string>16进制接收</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckHexSend">
|
||||
<property name="text">
|
||||
<string>16进制发送</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckAscii">
|
||||
<property name="text">
|
||||
<string>Ascii控制字符</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckShow">
|
||||
<property name="text">
|
||||
<string>暂停显示</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckDebug">
|
||||
<property name="text">
|
||||
<string>模拟设备</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckAutoSend">
|
||||
<property name="text">
|
||||
<string>定时发送</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cboxInterval"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labServerIP">
|
||||
<property name="text">
|
||||
<string>服务器IP地址</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtServerIP"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labServerPort">
|
||||
<property name="text">
|
||||
<string>服务器端口</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtServerPort"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnConnect">
|
||||
<property name="text">
|
||||
<string>连接</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSave">
|
||||
<property name="text">
|
||||
<string>保存</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnClear">
|
||||
<property name="text">
|
||||
<string>清空</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QHBoxLayout" name="layTcpClient">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cboxData">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSend">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>发送</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,232 @@
|
|||
#include "frmtcpserver.h"
|
||||
#include "ui_frmtcpserver.h"
|
||||
#include "quiwidget.h"
|
||||
|
||||
frmTcpServer::frmTcpServer(QWidget *parent) : QWidget(parent), ui(new Ui::frmTcpServer)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->initForm();
|
||||
this->initConfig();
|
||||
}
|
||||
|
||||
frmTcpServer::~frmTcpServer()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void frmTcpServer::initForm()
|
||||
{
|
||||
isOk = false;
|
||||
tcpServer = new TcpServer(this);
|
||||
connect(tcpServer, SIGNAL(clientConnected(QString, int)), this, SLOT(clientConnected(QString, int)));
|
||||
connect(tcpServer, SIGNAL(clientDisconnected(QString, int)), this, SLOT(clientDisconnected(QString, int)));
|
||||
connect(tcpServer, SIGNAL(sendData(QString, int, QString)), this, SLOT(sendData(QString, int, QString)));
|
||||
connect(tcpServer, SIGNAL(receiveData(QString, int, QString)), this, SLOT(receiveData(QString, int, QString)));
|
||||
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
|
||||
|
||||
ui->cboxInterval->addItems(App::Intervals);
|
||||
ui->cboxData->addItems(App::Datas);
|
||||
QUIHelper::setLabStyle(ui->labCount, 3);
|
||||
}
|
||||
|
||||
void frmTcpServer::initConfig()
|
||||
{
|
||||
ui->ckHexSend->setChecked(App::HexSendTcpServer);
|
||||
connect(ui->ckHexSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckHexReceive->setChecked(App::HexReceiveTcpServer);
|
||||
connect(ui->ckHexReceive, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckAscii->setChecked(App::AsciiTcpServer);
|
||||
connect(ui->ckAscii, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckDebug->setChecked(App::DebugTcpServer);
|
||||
connect(ui->ckDebug, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckAutoSend->setChecked(App::AutoSendTcpServer);
|
||||
connect(ui->ckAutoSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckSelectAll->setChecked(App::SelectAllTcpServer);
|
||||
connect(ui->ckSelectAll, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(App::IntervalTcpServer)));
|
||||
connect(ui->cboxInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtListenPort->setText(QString::number(App::TcpListenPort));
|
||||
connect(ui->txtListenPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
timer->setInterval(App::IntervalTcpServer);
|
||||
App::AutoSendTcpServer ? timer->start() : timer->stop();
|
||||
}
|
||||
|
||||
void frmTcpServer::saveConfig()
|
||||
{
|
||||
App::HexSendTcpServer = ui->ckHexSend->isChecked();
|
||||
App::HexReceiveTcpServer = ui->ckHexReceive->isChecked();
|
||||
App::AsciiTcpServer = ui->ckAscii->isChecked();
|
||||
App::DebugTcpServer = ui->ckDebug->isChecked();
|
||||
App::AutoSendTcpServer = ui->ckAutoSend->isChecked();
|
||||
App::SelectAllTcpServer = ui->ckSelectAll->isChecked();
|
||||
App::IntervalTcpServer = ui->cboxInterval->currentText().toInt();
|
||||
App::TcpListenPort = ui->txtListenPort->text().trimmed().toInt();
|
||||
App::writeConfig();
|
||||
|
||||
timer->setInterval(App::IntervalTcpServer);
|
||||
App::AutoSendTcpServer ? timer->start() : timer->stop();
|
||||
}
|
||||
|
||||
void frmTcpServer::append(int type, const QString &data, bool clear)
|
||||
{
|
||||
static int currentCount = 0;
|
||||
static int maxCount = 100;
|
||||
|
||||
if (clear) {
|
||||
ui->txtMain->clear();
|
||||
currentCount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentCount >= maxCount) {
|
||||
ui->txtMain->clear();
|
||||
currentCount = 0;
|
||||
}
|
||||
|
||||
if (ui->ckShow->isChecked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//过滤回车换行符
|
||||
QString strData = data;
|
||||
strData = strData.replace("\r", "");
|
||||
strData = strData.replace("\n", "");
|
||||
|
||||
//不同类型不同颜色显示
|
||||
QString strType;
|
||||
if (type == 0) {
|
||||
strType = "发送";
|
||||
ui->txtMain->setTextColor(QColor("darkgreen"));
|
||||
} else {
|
||||
strType = "接收";
|
||||
ui->txtMain->setTextColor(QColor("red"));
|
||||
}
|
||||
|
||||
strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData);
|
||||
ui->txtMain->append(strData);
|
||||
currentCount++;
|
||||
}
|
||||
|
||||
void frmTcpServer::sendData(const QString &data)
|
||||
{
|
||||
if (ui->ckSelectAll->isChecked()) {
|
||||
tcpServer->writeData(data);
|
||||
} else {
|
||||
int row = ui->listWidget->currentRow();
|
||||
if (row >= 0) {
|
||||
QString str = ui->listWidget->item(row)->text();
|
||||
QStringList list = str.split(":");
|
||||
tcpServer->writeData(list.at(0), list.at(1).toInt(), data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void frmTcpServer::clientConnected(const QString &ip, int port)
|
||||
{
|
||||
QString str = QString("%1:%2").arg(ip).arg(port);
|
||||
ui->listWidget->addItem(str);
|
||||
ui->labCount->setText(QString("共 %1 个连接").arg(ui->listWidget->count()));
|
||||
}
|
||||
|
||||
void frmTcpServer::clientDisconnected(const QString &ip, int port)
|
||||
{
|
||||
int row = -1;
|
||||
QString str = QString("%1:%2").arg(ip).arg(port);
|
||||
for (int i = 0; i < ui->listWidget->count(); i++) {
|
||||
if (ui->listWidget->item(i)->text() == str) {
|
||||
row = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete ui->listWidget->takeItem(row);
|
||||
ui->labCount->setText(QString("共 %1 个连接").arg(ui->listWidget->count()));
|
||||
}
|
||||
|
||||
void frmTcpServer::sendData(const QString &ip, int port, const QString &data)
|
||||
{
|
||||
QString str = QString("[%1:%2] %3").arg(ip).arg(port).arg(data);
|
||||
bool error = (data.contains("下线") || data.contains("离线"));
|
||||
append(error ? 1 : 0, str);
|
||||
}
|
||||
|
||||
void frmTcpServer::receiveData(const QString &ip, int port, const QString &data)
|
||||
{
|
||||
QString str = QString("[%1:%2] %3").arg(ip).arg(port).arg(data);
|
||||
append(1, str);
|
||||
}
|
||||
|
||||
void frmTcpServer::on_btnListen_clicked()
|
||||
{
|
||||
if (ui->btnListen->text() == "监听") {
|
||||
isOk = tcpServer->start();
|
||||
if (isOk) {
|
||||
append(0, "监听成功");
|
||||
ui->btnListen->setText("关闭");
|
||||
}
|
||||
} else {
|
||||
isOk = false;
|
||||
tcpServer->stop();
|
||||
ui->btnListen->setText("监听");
|
||||
}
|
||||
}
|
||||
|
||||
void frmTcpServer::on_btnSave_clicked()
|
||||
{
|
||||
QString data = ui->txtMain->toPlainText();
|
||||
if (data.length() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString fileName = QString("%1/%2.txt").arg(QUIHelper::appPath()).arg(STRDATETIME);
|
||||
QFile file(fileName);
|
||||
if (file.open(QFile::WriteOnly | QFile::Text)) {
|
||||
file.write(data.toUtf8());
|
||||
file.close();
|
||||
}
|
||||
|
||||
on_btnClear_clicked();
|
||||
}
|
||||
|
||||
void frmTcpServer::on_btnClear_clicked()
|
||||
{
|
||||
append(0, "", true);
|
||||
}
|
||||
|
||||
void frmTcpServer::on_btnSend_clicked()
|
||||
{
|
||||
if (!isOk) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString data = ui->cboxData->currentText();
|
||||
if (data.length() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendData(data);
|
||||
}
|
||||
|
||||
void frmTcpServer::on_btnClose_clicked()
|
||||
{
|
||||
if (ui->ckSelectAll->isChecked()) {
|
||||
tcpServer->remove();
|
||||
} else {
|
||||
int row = ui->listWidget->currentRow();
|
||||
if (row >= 0) {
|
||||
QString str = ui->listWidget->item(row)->text();
|
||||
QStringList list = str.split(":");
|
||||
tcpServer->remove(list.at(0), list.at(1).toInt());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef FRMTCPSERVER_H
|
||||
#define FRMTCPSERVER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "tcpserver.h"
|
||||
|
||||
namespace Ui {
|
||||
class frmTcpServer;
|
||||
}
|
||||
|
||||
class frmTcpServer : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit frmTcpServer(QWidget *parent = 0);
|
||||
~frmTcpServer();
|
||||
|
||||
private:
|
||||
Ui::frmTcpServer *ui;
|
||||
|
||||
bool isOk;
|
||||
TcpServer *tcpServer;
|
||||
QTimer *timer;
|
||||
|
||||
private slots:
|
||||
void initForm();
|
||||
void initConfig();
|
||||
void saveConfig();
|
||||
void append(int type, const QString &data, bool clear = false);
|
||||
|
||||
private slots:
|
||||
void sendData(const QString &data);
|
||||
|
||||
void clientConnected(const QString &ip, int port);
|
||||
void clientDisconnected(const QString &ip, int port);
|
||||
void sendData(const QString &ip, int port, const QString &data);
|
||||
void receiveData(const QString &ip, int port, const QString &data);
|
||||
|
||||
private slots:
|
||||
void on_btnListen_clicked();
|
||||
void on_btnSave_clicked();
|
||||
void on_btnClear_clicked();
|
||||
void on_btnSend_clicked();
|
||||
void on_btnClose_clicked();
|
||||
};
|
||||
|
||||
#endif // FRMTCPSERVER_H
|
|
@ -0,0 +1,229 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>frmTcpServer</class>
|
||||
<widget class="QWidget" name="frmTcpServer">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTextEdit" name="txtMain">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="2">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckHexReceive">
|
||||
<property name="text">
|
||||
<string>16进制接收</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckHexSend">
|
||||
<property name="text">
|
||||
<string>16进制发送</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckAscii">
|
||||
<property name="text">
|
||||
<string>Ascii控制字符</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckShow">
|
||||
<property name="text">
|
||||
<string>暂停显示</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckDebug">
|
||||
<property name="text">
|
||||
<string>模拟设备</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckAutoSend">
|
||||
<property name="text">
|
||||
<string>定时发送</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cboxInterval"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labListenPort">
|
||||
<property name="text">
|
||||
<string>监听端口</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtListenPort"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnListen">
|
||||
<property name="text">
|
||||
<string>监听</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSave">
|
||||
<property name="text">
|
||||
<string>保存</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnClear">
|
||||
<property name="text">
|
||||
<string>清空</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnClose">
|
||||
<property name="text">
|
||||
<string>断开</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labCount">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>共 0 个连接</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="listWidget"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckSelectAll">
|
||||
<property name="text">
|
||||
<string>对所有已连接客户端</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QHBoxLayout" name="layTcpServer">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cboxData">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSend">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>发送</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,224 @@
|
|||
#include "frmudpserver.h"
|
||||
#include "ui_frmudpserver.h"
|
||||
#include "quiwidget.h"
|
||||
|
||||
frmUdpServer::frmUdpServer(QWidget *parent) : QWidget(parent), ui(new Ui::frmUdpServer)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->initForm();
|
||||
this->initConfig();
|
||||
}
|
||||
|
||||
frmUdpServer::~frmUdpServer()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void frmUdpServer::initForm()
|
||||
{
|
||||
udpSocket = new QUdpSocket(this);
|
||||
connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readData()));
|
||||
|
||||
timer = new QTimer(this);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnSend_clicked()));
|
||||
|
||||
ui->cboxInterval->addItems(App::Intervals);
|
||||
ui->cboxData->addItems(App::Datas);
|
||||
}
|
||||
|
||||
void frmUdpServer::initConfig()
|
||||
{
|
||||
ui->ckHexSend->setChecked(App::HexSendUdpServer);
|
||||
connect(ui->ckHexSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckHexReceive->setChecked(App::HexReceiveUdpServer);
|
||||
connect(ui->ckHexReceive, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckAscii->setChecked(App::AsciiUdpServer);
|
||||
connect(ui->ckAscii, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckDebug->setChecked(App::DebugUdpServer);
|
||||
connect(ui->ckDebug, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->ckAutoSend->setChecked(App::AutoSendUdpServer);
|
||||
connect(ui->ckAutoSend, SIGNAL(stateChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->cboxInterval->setCurrentIndex(ui->cboxInterval->findText(QString::number(App::IntervalUdpServer)));
|
||||
connect(ui->cboxInterval, SIGNAL(currentIndexChanged(int)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtServerIP->setText(App::UdpServerIP);
|
||||
connect(ui->txtServerIP, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtServerPort->setText(QString::number(App::UdpServerPort));
|
||||
connect(ui->txtServerPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
ui->txtListenPort->setText(QString::number(App::UdpListenPort));
|
||||
connect(ui->txtListenPort, SIGNAL(textChanged(QString)), this, SLOT(saveConfig()));
|
||||
|
||||
timer->setInterval(App::IntervalUdpServer);
|
||||
App::AutoSendUdpServer ? timer->start() : timer->stop();
|
||||
}
|
||||
|
||||
void frmUdpServer::saveConfig()
|
||||
{
|
||||
App::HexSendUdpServer = ui->ckHexSend->isChecked();
|
||||
App::HexReceiveUdpServer = ui->ckHexReceive->isChecked();
|
||||
App::AsciiUdpServer = ui->ckAscii->isChecked();
|
||||
App::DebugUdpServer = ui->ckDebug->isChecked();
|
||||
App::AutoSendUdpServer = ui->ckAutoSend->isChecked();
|
||||
App::IntervalUdpServer = ui->cboxInterval->currentText().toInt();
|
||||
App::UdpServerIP = ui->txtServerIP->text().trimmed();
|
||||
App::UdpServerPort = ui->txtServerPort->text().trimmed().toInt();
|
||||
App::UdpListenPort = ui->txtListenPort->text().trimmed().toInt();
|
||||
App::writeConfig();
|
||||
|
||||
timer->setInterval(App::IntervalUdpServer);
|
||||
App::AutoSendUdpServer ? timer->start() : timer->stop();
|
||||
}
|
||||
|
||||
void frmUdpServer::append(int type, const QString &data, bool clear)
|
||||
{
|
||||
static int currentCount = 0;
|
||||
static int maxCount = 100;
|
||||
|
||||
if (clear) {
|
||||
ui->txtMain->clear();
|
||||
currentCount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentCount >= maxCount) {
|
||||
ui->txtMain->clear();
|
||||
currentCount = 0;
|
||||
}
|
||||
|
||||
if (ui->ckShow->isChecked()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//过滤回车换行符
|
||||
QString strData = data;
|
||||
strData = strData.replace("\r", "");
|
||||
strData = strData.replace("\n", "");
|
||||
|
||||
//不同类型不同颜色显示
|
||||
QString strType;
|
||||
if (type == 0) {
|
||||
strType = "发送";
|
||||
ui->txtMain->setTextColor(QColor("darkgreen"));
|
||||
} else {
|
||||
strType = "接收";
|
||||
ui->txtMain->setTextColor(QColor("red"));
|
||||
}
|
||||
|
||||
strData = QString("时间[%1] %2: %3").arg(TIMEMS).arg(strType).arg(strData);
|
||||
ui->txtMain->append(strData);
|
||||
currentCount++;
|
||||
}
|
||||
|
||||
void frmUdpServer::readData()
|
||||
{
|
||||
QHostAddress host;
|
||||
quint16 port;
|
||||
QByteArray data;
|
||||
QString buffer;
|
||||
|
||||
while (udpSocket->hasPendingDatagrams()) {
|
||||
data.resize(udpSocket->pendingDatagramSize());
|
||||
udpSocket->readDatagram(data.data(), data.size(), &host, &port);
|
||||
|
||||
if (App::HexReceiveUdpServer) {
|
||||
buffer = QUIHelper::byteArrayToHexStr(data);
|
||||
} else if (App::AsciiUdpServer) {
|
||||
buffer = QUIHelper::byteArrayToAsciiStr(data);
|
||||
} else {
|
||||
buffer = QString(data);
|
||||
}
|
||||
|
||||
QString ip = host.toString();
|
||||
if (ip.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString str = QString("[%1:%2] %3").arg(ip).arg(port).arg(buffer);
|
||||
append(1, str);
|
||||
|
||||
if (App::DebugUdpServer) {
|
||||
int count = App::Keys.count();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (App::Keys.at(i) == buffer) {
|
||||
sendData(ip, port, App::Values.at(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void frmUdpServer::sendData(const QString &ip, int port, const QString &data)
|
||||
{
|
||||
QByteArray buffer;
|
||||
if (App::HexSendUdpServer) {
|
||||
buffer = QUIHelper::hexStrToByteArray(data);
|
||||
} else if (App::AsciiUdpServer) {
|
||||
buffer = QUIHelper::asciiStrToByteArray(data);
|
||||
} else {
|
||||
buffer = data.toLatin1();
|
||||
}
|
||||
|
||||
udpSocket->writeDatagram(buffer, QHostAddress(ip), port);
|
||||
|
||||
QString str = QString("[%1:%2] %3").arg(ip).arg(port).arg(data);
|
||||
append(0, str);
|
||||
|
||||
}
|
||||
|
||||
void frmUdpServer::on_btnListen_clicked()
|
||||
{
|
||||
if (ui->btnListen->text() == "监听") {
|
||||
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
|
||||
bool ok = udpSocket->bind(QHostAddress::AnyIPv4, App::UdpListenPort);
|
||||
#else
|
||||
bool ok = udpSocket->bind(QHostAddress::Any, App::UdpListenPort);
|
||||
#endif
|
||||
if (ok) {
|
||||
ui->btnListen->setText("关闭");
|
||||
append(0, "监听成功");
|
||||
}
|
||||
} else {
|
||||
udpSocket->abort();
|
||||
ui->btnListen->setText("监听");
|
||||
}
|
||||
}
|
||||
|
||||
void frmUdpServer::on_btnSave_clicked()
|
||||
{
|
||||
QString data = ui->txtMain->toPlainText();
|
||||
if (data.length() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString fileName = QString("%1/%2.txt").arg(QUIHelper::appPath()).arg(STRDATETIME);
|
||||
QFile file(fileName);
|
||||
if (file.open(QFile::WriteOnly | QFile::Text)) {
|
||||
file.write(data.toUtf8());
|
||||
file.close();
|
||||
}
|
||||
|
||||
on_btnClear_clicked();
|
||||
}
|
||||
|
||||
void frmUdpServer::on_btnClear_clicked()
|
||||
{
|
||||
append(0, "", true);
|
||||
}
|
||||
|
||||
void frmUdpServer::on_btnSend_clicked()
|
||||
{
|
||||
QString data = ui->cboxData->currentText();
|
||||
if (data.length() <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendData(App::UdpServerIP, App::UdpServerPort, data);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef FRMUDPSERVER_H
|
||||
#define FRMUDPSERVER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QtNetwork>
|
||||
|
||||
namespace Ui {
|
||||
class frmUdpServer;
|
||||
}
|
||||
|
||||
class frmUdpServer : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit frmUdpServer(QWidget *parent = 0);
|
||||
~frmUdpServer();
|
||||
|
||||
private:
|
||||
Ui::frmUdpServer *ui;
|
||||
|
||||
QUdpSocket *udpSocket;
|
||||
QTimer *timer;
|
||||
|
||||
private slots:
|
||||
void initForm();
|
||||
void initConfig();
|
||||
void saveConfig();
|
||||
void append(int type, const QString &data, bool clear = false);
|
||||
|
||||
void readData();
|
||||
void sendData(const QString &ip, int port, const QString &data);
|
||||
|
||||
private slots:
|
||||
void on_btnListen_clicked();
|
||||
void on_btnSave_clicked();
|
||||
void on_btnClear_clicked();
|
||||
void on_btnSend_clicked();
|
||||
};
|
||||
|
||||
#endif // FRMUDPSERVER_H
|
|
@ -0,0 +1,211 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>frmUdpServer</class>
|
||||
<widget class="QWidget" name="frmUdpServer">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTextEdit" name="txtMain">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="2">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckHexReceive">
|
||||
<property name="text">
|
||||
<string>16进制接收</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckHexSend">
|
||||
<property name="text">
|
||||
<string>16进制发送</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckAscii">
|
||||
<property name="text">
|
||||
<string>Ascii控制字符</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckShow">
|
||||
<property name="text">
|
||||
<string>暂停显示</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckDebug">
|
||||
<property name="text">
|
||||
<string>模拟设备</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="ckAutoSend">
|
||||
<property name="text">
|
||||
<string>定时发送</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cboxInterval"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labServerIP">
|
||||
<property name="text">
|
||||
<string>远程IP地址</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtServerIP"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labServerPort">
|
||||
<property name="text">
|
||||
<string>远程端口</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtServerPort"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="labListenPort">
|
||||
<property name="text">
|
||||
<string>监听端口</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtListenPort"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnListen">
|
||||
<property name="text">
|
||||
<string>监听</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSave">
|
||||
<property name="text">
|
||||
<string>保存</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnClear">
|
||||
<property name="text">
|
||||
<string>清空</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QHBoxLayout" name="layUdpServer">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cboxData">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSend">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>发送</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,11 @@
|
|||
#include <QtCore>
|
||||
#include <QtGui>
|
||||
#include <QtNetwork>
|
||||
|
||||
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
|
||||
#include <QtWidgets>
|
||||
#endif
|
||||
|
||||
#include "app.h"
|
||||
|
||||
#pragma execution_character_set("utf-8")
|
|
@ -0,0 +1,31 @@
|
|||
#include "frmmain.h"
|
||||
#include "quiwidget.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
a.setWindowIcon(QIcon(":/main.ico"));
|
||||
|
||||
QFont font;
|
||||
font.setFamily(QUIConfig::FontName);
|
||||
font.setPixelSize(QUIConfig::FontSize);
|
||||
a.setFont(font);
|
||||
|
||||
//设置编码以及加载中文翻译文件
|
||||
QUIHelper::setCode();
|
||||
QUIHelper::setTranslator(":/qt_zh_CN.qm");
|
||||
QUIHelper::setTranslator(":/widgets.qm");
|
||||
QUIHelper::initRand();
|
||||
|
||||
App::Intervals << "1" << "10" << "20" << "50" << "100" << "200" << "300" << "500" << "1000" << "1500" << "2000" << "3000" << "5000" << "10000";
|
||||
App::ConfigFile = QString("%1/%2.ini").arg(QUIHelper::appPath()).arg(QUIHelper::appName());
|
||||
App::readConfig();
|
||||
App::readSendData();
|
||||
App::readDeviceData();
|
||||
|
||||
frmMain w;
|
||||
w.setWindowTitle(QString("网络调试助手V2019 本机IP: %1 QQ: 517216493").arg(QUIHelper::getLocalIP()));
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2016-09-19T13:33:20
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui network
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = nettool
|
||||
TEMPLATE = app
|
||||
MOC_DIR = temp/moc
|
||||
RCC_DIR = temp/rcc
|
||||
UI_DIR = temp/ui
|
||||
OBJECTS_DIR = temp/obj
|
||||
DESTDIR = bin
|
||||
win32:RC_FILE = other/main.rc
|
||||
|
||||
SOURCES += main.cpp
|
||||
HEADERS += head.h
|
||||
RESOURCES += other/main.qrc
|
||||
CONFIG += warn_off
|
||||
|
||||
include ($$PWD/api/api.pri)
|
||||
include ($$PWD/form/form.pri)
|
||||
|
||||
INCLUDEPATH += $$PWD
|
||||
INCLUDEPATH += $$PWD/api
|
||||
INCLUDEPATH += $$PWD/form
|
Binary file not shown.
After Width: | Height: | Size: 91 KiB |
|
@ -0,0 +1,7 @@
|
|||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>main.ico</file>
|
||||
<file>qt_zh_CN.qm</file>
|
||||
<file>widgets.qm</file>
|
||||
</qresource>
|
||||
</RCC>
|
|
@ -0,0 +1 @@
|
|||
IDI_ICON1 ICON DISCARDABLE "main.ico"
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,17 @@
|
|||
时隔半年,对网络调试助手工具进行所有代码重写,这次目录结果整齐的一逼,代码整齐的一逼,非常完善了,打死也不再改版了。这次真的打死也不再改版了。
|
||||
|
||||
旧版本:http://www.qtcn.org/bbs/read-htm-tid-55540.html
|
||||
|
||||
基本功能:
|
||||
1:16进制数据和ASCII数据收发。
|
||||
2:定时器自动发送。
|
||||
3:自动从配置文件加载最后一次的界面设置。
|
||||
4:自动从配置文件加载数据发送下拉框的数据。可以将经常使用的数据填写在send.txt中。
|
||||
5:可启用设备模拟回复,当收到某个数据时,模拟设备自动回复数据。对应数据格式填写在device.txt中。
|
||||
6:可对单个在线连接发送数据,也可勾选全部进行发送。
|
||||
7:支持多个客户端连接并发。
|
||||
8:采用单线程。
|
||||
9:四种模式,tcp服务器、tcp客户端、udp服务器、udp客户端。
|
||||
|
||||
编译后请将源码下的file目录中的所有文件复制到可执行文件同一目录。
|
||||
如果有更好的建议或者意见,请Q我(517216493),谢谢!
|
Binary file not shown.
After Width: | Height: | Size: 53 KiB |
Binary file not shown.
After Width: | Height: | Size: 63 KiB |
Binary file not shown.
After Width: | Height: | Size: 64 KiB |
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
Loading…
Reference in New Issue