Skip to content

Commit

Permalink
保留设置
Browse files Browse the repository at this point in the history
  • Loading branch information
才明洋 committed Jan 22, 2018
1 parent 0e69ec5 commit ee1e9d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion mainwidget.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "mainwidget.h"

MainWidget::MainWidget(QWidget *parent)
: QWidget(parent)
: QWidget(parent), settings("TurnMeOn", "SerialAsst")
{
//初始化各参数列表
BaudrateList<<"256000"<<"230400"<<"128000"<<"115200"<<"76800"<<"57600"
Expand All @@ -14,12 +14,16 @@ MainWidget::MainWidget(QWidget *parent)
COMBox = new QComboBox();
BaudrateBox = new QComboBox();
BaudrateBox->addItems(BaudrateList);
BaudrateBox->setCurrentIndex(settings.value("Baud rate", 0).toInt());
StopbitsBox = new QComboBox();
StopbitsBox->addItems(StopbitsList);
StopbitsBox->setCurrentIndex(settings.value("Stop bits", 0).toInt());
DatabitsBox = new QComboBox();
DatabitsBox->addItems(DatabitsList);
DatabitsBox->setCurrentIndex(settings.value("Data bits", 0).toInt());
ParityBox = new QComboBox();
ParityBox->addItems(ParityList);
ParityBox->setCurrentIndex(settings.value("Parity", 0).toInt());

//初始化label
BaudrateLabel = new QLabel(tr("波特率"));
Expand Down Expand Up @@ -137,6 +141,7 @@ MainWidget::MainWidget(QWidget *parent)
connect(ParityBox, QComboBox::currentTextChanged, serialController, SerialController::getParity);
connect(this, sendData, serialController, SerialController::writeData);
connect(serialController, SerialController::recvData, this, getRecv);

}

void MainWidget::CheckSerials()
Expand Down Expand Up @@ -174,6 +179,10 @@ void MainWidget::CheckSerials()
MainWidget::~MainWidget()
{
SerialThr.terminate();
settings.setValue("Baud rate", BaudrateBox->currentIndex());
settings.setValue("Stop bits", StopbitsBox->currentIndex());
settings.setValue("Data bits", DatabitsBox->currentIndex());
settings.setValue("Parity", ParityBox->currentIndex());
}

void MainWidget::serialOpened()
Expand Down
2 changes: 2 additions & 0 deletions mainwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <QThread>
#include <QDateTime>
#include <QByteArray>
#include <QSettings>
#include "serialcontroller.h"


Expand Down Expand Up @@ -71,6 +72,7 @@ public slots:
QTimer *CheckTimer, *SendTimer;
SerialController *serialController;
QThread SerialThr;
QSettings settings;

bool isSendNewLine = false;
bool isSendHex = false;
Expand Down

0 comments on commit ee1e9d4

Please sign in to comment.