Skip to content

Commit

Permalink
Add length limit of name
Browse files Browse the repository at this point in the history
  • Loading branch information
wh201906 committed Jun 17, 2023
1 parent 78d2322 commit 72f6e45
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Qt/w820nbplusform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ W820NBPlusForm::W820NBPlusForm(QWidget *parent) :
{
ui->setupUi(this);

ui->nameEdit->setMaxLength(m_maxNameLength);

connect(ui->noiseNormalButton, &QRadioButton::clicked, this, &W820NBPlusForm::onBtnInNoiseGroupClicked);
connect(ui->noiseReductionButton, &QRadioButton::clicked, this, &W820NBPlusForm::onBtnInNoiseGroupClicked);
connect(ui->noiseAmbientSoundButton, &QRadioButton::clicked, this, &W820NBPlusForm::onBtnInNoiseGroupClicked);
Expand Down Expand Up @@ -201,6 +203,14 @@ void W820NBPlusForm::on_nameSetButton_clicked()
QString name = ui->nameEdit->text();
if(name.isEmpty())
return;
QByteArray nameBytes = name.toUtf8();
// max length can be 24, 29, 30 or 35
// the max length of W820NB Plus is 30(defined in w820nbplusform.h)
if(nameBytes.length() > m_maxNameLength)
{
emit showMessage(tr("The name is too long."));
return;
}
QByteArray cmd = "\xCA";
cmd += name.toUtf8();
emit sendCommand(cmd);
Expand Down
1 change: 1 addition & 0 deletions Qt/w820nbplusform.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public slots:
void readSettings();
private:
Ui::W820NBPlusForm *ui;
int m_maxNameLength = 30;

signals:
void sendCommand(const QByteArray& cmd, bool isRaw = false);
Expand Down

0 comments on commit 72f6e45

Please sign in to comment.