打开串口失败时声音提示
This commit is contained in:
+46
-40
@@ -43,7 +43,7 @@ MainWidget::MainWidget(QWidget *parent)
|
||||
ParityBox->setCurrentIndex(settings.value("Parity", 0).toInt());
|
||||
|
||||
//初始化label
|
||||
COMLabel = new QLabel(tr("串口"));
|
||||
COMLabel = new QLabel(tr("串口号"));
|
||||
BaudrateLabel = new QLabel(tr("波特率"));
|
||||
StopbitsLabel = new QLabel(tr("停止位"));
|
||||
DatabitsLabel = new QLabel(tr("数据位"));
|
||||
@@ -66,11 +66,13 @@ MainWidget::MainWidget(QWidget *parent)
|
||||
SendButton = new QPushButton(tr("发送"));
|
||||
SendButton->setDisabled(true);
|
||||
SendButton->setToolTip(tr("Ctrl+Enter"));
|
||||
ClearButton = new QPushButton(tr("清除接收"));
|
||||
ClearRecvButton = new QPushButton(tr("清除接收"));
|
||||
ClearSendButton = new QPushButton(tr("清除发送"));
|
||||
|
||||
connect(OpenButton, QPushButton::clicked, this, OpenSerial);
|
||||
connect(SendButton, QPushButton::clicked, this, SendContent);
|
||||
connect(ClearButton, QPushButton::clicked, this, ClearRecv);
|
||||
connect(ClearRecvButton, QPushButton::clicked, this, ClearRecv);
|
||||
connect(ClearSendButton, QPushButton::clicked, this, ClearSend);
|
||||
|
||||
//复选框
|
||||
NewLineBox = new QCheckBox(tr("发送新行"));
|
||||
@@ -98,58 +100,56 @@ MainWidget::MainWidget(QWidget *parent)
|
||||
this, changeSendTimer);
|
||||
|
||||
//初始化布局
|
||||
flayout = new QFormLayout();
|
||||
flayout->addRow(BaudrateLabel, BaudrateBox);
|
||||
flayout->addRow(StopbitsLabel, StopbitsBox);
|
||||
flayout->addRow(DatabitsLabel, DatabitsBox);
|
||||
flayout->addRow(ParityLabel, ParityBox);
|
||||
flayout->addRow(COMLabel, COMBox);
|
||||
flayout->addRow(OpenButton);
|
||||
flayout->setAlignment(OpenButton, Qt::AlignVCenter);
|
||||
// flayout->setSpacing(50);
|
||||
flayout->setMargin(30);
|
||||
flayout->setHorizontalSpacing(20);
|
||||
flayout->setVerticalSpacing(60);
|
||||
leftLlayout = new QFormLayout();
|
||||
leftLlayout->addRow(BaudrateLabel, BaudrateBox);
|
||||
leftLlayout->addRow(StopbitsLabel, StopbitsBox);
|
||||
leftLlayout->addRow(DatabitsLabel, DatabitsBox);
|
||||
leftLlayout->addRow(ParityLabel, ParityBox);
|
||||
leftLlayout->addRow(COMLabel, COMBox);
|
||||
leftLlayout->addRow(OpenButton);
|
||||
leftLlayout->setAlignment(OpenButton, Qt::AlignVCenter);
|
||||
leftLlayout->setMargin(30);
|
||||
leftLlayout->setHorizontalSpacing(20);
|
||||
leftLlayout->setVerticalSpacing(60);
|
||||
|
||||
paramGroup = new QGroupBox();
|
||||
paramGroup->setLayout(flayout);
|
||||
paramGroup->setLayout(leftLlayout);
|
||||
paramGroup->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
cvlayout = new QVBoxLayout();
|
||||
cvlayout->addWidget(RecvArea, 7);
|
||||
cvlayout->addWidget(SendArea, 2);
|
||||
// RecvArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
// SendArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
hlayout = new QHBoxLayout();
|
||||
hlayout->addWidget(HexSend);
|
||||
hlayout->addWidget(NewLineBox, 0, Qt::AlignLeft);
|
||||
hlayout->addWidget(TimerBox, 0, Qt::AlignRight);
|
||||
hlayout->addWidget(TimerSpin, 0, Qt::AlignLeft);
|
||||
hlayout->addWidget(SendButton, 0, Qt::AlignRight);
|
||||
bottomLayout = new QHBoxLayout();
|
||||
bottomLayout->addWidget(ClearSendButton, 0, Qt::AlignLeft);
|
||||
bottomLayout->addWidget(HexSend);
|
||||
bottomLayout->addWidget(NewLineBox, 0, Qt::AlignLeft);
|
||||
bottomLayout->addWidget(TimerBox, 0, Qt::AlignRight);
|
||||
bottomLayout->addWidget(TimerSpin, 1, Qt::AlignLeft);
|
||||
bottomLayout->addWidget(SendButton, 0, Qt::AlignRight);
|
||||
|
||||
rvlayout = new QVBoxLayout();
|
||||
rvlayout->addWidget(ClearButton, 0, Qt::AlignCenter);
|
||||
rvlayout->addWidget(HexRecv);
|
||||
rvlayout->addWidget(RTSBox);
|
||||
rvlayout->addWidget(DTRBox);
|
||||
rightLayout = new QVBoxLayout();
|
||||
rightLayout->addWidget(ClearRecvButton, 0, Qt::AlignCenter);
|
||||
rightLayout->addWidget(HexRecv);
|
||||
rightLayout->addWidget(RTSBox);
|
||||
rightLayout->addWidget(DTRBox);
|
||||
|
||||
layout = new QGridLayout(this);
|
||||
centralLayout = new QGridLayout(this);
|
||||
|
||||
// layout->addLayout(flayout, 0, 0, 2, 1);
|
||||
layout->addWidget(paramGroup, 0, 0, 2, 1);
|
||||
layout->addLayout(hlayout, 1, 1);
|
||||
layout->addLayout(cvlayout, 0, 1, 1, 1);
|
||||
layout->addLayout(rvlayout, 0, 2, Qt::AlignTop);
|
||||
centralLayout->addWidget(paramGroup, 0, 0, 2, 1);
|
||||
centralLayout->addLayout(bottomLayout, 1, 1);
|
||||
centralLayout->addLayout(cvlayout, 0, 1, 1, 1);
|
||||
centralLayout->addLayout(rightLayout, 0, 2, Qt::AlignTop);
|
||||
|
||||
layout->setColumnMinimumWidth(0, 150);
|
||||
layout->setColumnMinimumWidth(2, 100);
|
||||
centralLayout->setColumnMinimumWidth(0, 150);
|
||||
centralLayout->setColumnMinimumWidth(2, 100);
|
||||
|
||||
layout->setColumnStretch(0, 0);
|
||||
layout->setColumnStretch(1, 2);
|
||||
layout->setColumnStretch(2, 0);
|
||||
centralLayout->setColumnStretch(0, 0);
|
||||
centralLayout->setColumnStretch(1, 2);
|
||||
centralLayout->setColumnStretch(2, 0);
|
||||
|
||||
setLayout(layout);
|
||||
setLayout(centralLayout);
|
||||
|
||||
//计时器 初始化
|
||||
CheckTimer = new QTimer(this);
|
||||
@@ -246,6 +246,7 @@ void MainWidget::serialOpened()
|
||||
void MainWidget::serialNotOpened()
|
||||
{
|
||||
emit sendStatus(tr("串口打开失败"));
|
||||
QApplication::beep();
|
||||
}
|
||||
|
||||
void MainWidget::serialClosed()
|
||||
@@ -286,6 +287,11 @@ void MainWidget::ClearRecv()
|
||||
RecvArea->clear();
|
||||
}
|
||||
|
||||
void MainWidget::ClearSend()
|
||||
{
|
||||
SendArea->clear();
|
||||
}
|
||||
|
||||
void MainWidget::detNewLine(int state)
|
||||
{
|
||||
if (state == 2)
|
||||
|
||||
+7
-5
@@ -4,6 +4,7 @@
|
||||
#include <QWidget>
|
||||
#include <QComboBox>
|
||||
#include <QGridLayout>
|
||||
#include <QApplication>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QTextEdit>
|
||||
@@ -54,6 +55,7 @@ public slots:
|
||||
void OpenSerial();
|
||||
void CloseSerial();
|
||||
void ClearRecv();
|
||||
void ClearSend();
|
||||
void detNewLine(int state); //处理发送新行
|
||||
void ControlSendTimer(int state);
|
||||
void changeSendTimer();
|
||||
@@ -67,13 +69,13 @@ private:
|
||||
QStringList BaudrateList, StopbitsList, DatabitsList, ParityList;
|
||||
QStringList COMList, PortNameList, DescList;
|
||||
QLabel *COMLabel, *BaudrateLabel, *StopbitsLabel, *DatabitsLabel, *ParityLabel;
|
||||
QGridLayout *layout;
|
||||
QVBoxLayout *cvlayout, *rvlayout;
|
||||
QHBoxLayout *hlayout;
|
||||
QFormLayout *flayout;
|
||||
QGridLayout *centralLayout;
|
||||
QVBoxLayout *cvlayout, *rightLayout;
|
||||
QHBoxLayout *bottomLayout;
|
||||
QFormLayout *leftLlayout;
|
||||
QGroupBox *paramGroup;
|
||||
QTextEdit *RecvArea, *SendArea;
|
||||
QPushButton *OpenButton, *SendButton, *ClearButton;
|
||||
QPushButton *OpenButton, *SendButton, *ClearRecvButton, *ClearSendButton;
|
||||
QCheckBox *NewLineBox, *TimerBox, *HexSend, *HexRecv, *RTSBox, *DTRBox;
|
||||
QSpinBox *TimerSpin;
|
||||
QTimer *CheckTimer, *SendTimer;
|
||||
|
||||
@@ -9,8 +9,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
|
||||
setStatusBar(statusbar);
|
||||
|
||||
aboutQtAct = new QAction(tr("&关于Qt"), this);
|
||||
aboutAct = new QAction(tr("&关于SerialAsst"), this);
|
||||
helpMenu = menuBar->addMenu(tr("&帮助"));
|
||||
helpMenu->addAction(aboutQtAct);
|
||||
helpMenu->addAction(aboutAct);
|
||||
setCentralWidget(widget);
|
||||
statusbar->showMessage(tr("准备就绪"));
|
||||
connect(widget, MainWidget::sendStatus, this, setNewMsg);
|
||||
@@ -19,6 +21,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
|
||||
timeLabel->setText(QDateTime::currentDateTime().toString());
|
||||
|
||||
connect(aboutQtAct, &QAction::triggered, this, &showAboutQt);
|
||||
connect(aboutAct, &QAction::triggered, this, showAbout);
|
||||
connect(widget, MainWidget::sendDateTime, this, setDateTime);
|
||||
resize(900, 600);
|
||||
}
|
||||
@@ -38,3 +41,8 @@ void MainWindow::showAboutQt()
|
||||
QMessageBox *aboutWindow = new QMessageBox(this);
|
||||
aboutWindow->aboutQt(this);
|
||||
}
|
||||
|
||||
void MainWindow::showAbout()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
+4
-3
@@ -17,15 +17,16 @@ public:
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void setNewMsg(QString msg);
|
||||
void setDateTime(QString datetime);
|
||||
void setNewMsg(QString msg); //设置状态栏信息
|
||||
void setDateTime(QString datetime); //设置状态栏时间
|
||||
void showAboutQt();
|
||||
void showAbout();
|
||||
|
||||
private:
|
||||
MainWidget *widget;
|
||||
QMenuBar *menuBar;
|
||||
QMenu *helpMenu;
|
||||
QAction *aboutQtAct;
|
||||
QAction *aboutQtAct, *aboutAct;
|
||||
QStatusBar *statusbar;
|
||||
QLabel *timeLabel;
|
||||
|
||||
|
||||
+2
-2
@@ -27,8 +27,8 @@ public slots:
|
||||
void getParity(QString parity); //改变校验位
|
||||
void writeData(QString content); //发送数据
|
||||
void handleRecv(); //接受数据
|
||||
void contrloRTS(bool set);
|
||||
void controlDTR(bool set);
|
||||
void contrloRTS(bool set); //设置RTS位
|
||||
void controlDTR(bool set); //设置DTR位
|
||||
|
||||
private:
|
||||
QSerialPort *serial;
|
||||
|
||||
Reference in New Issue
Block a user