qt/LedOK/wDevicesManager/specialdlg - 副本.cpp

76 lines
2.4 KiB
C++
Raw Normal View History

2022-01-04 18:11:48 +08:00
#include "specialdlg.h"
2022-08-25 18:37:24 +08:00
#include "tools.h"
#include "globaldefine.h"
#include "base/waitingdlg.h"
#include "LoUIClass/qiplineedit.h"
#include <QMessageBox>
#include <QMetaEnum>
2022-01-04 18:11:48 +08:00
2022-09-28 18:21:57 +08:00
SpecialDlg::SpecialDlg(QWidget *parent) : QDialog(parent) {
2022-08-25 18:37:24 +08:00
resize(300, 100);
setWindowTitle(tr("Specify IP"));
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
auto vBox = new QVBoxLayout(this);
vBox->addStretch();
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
auto hBox = new QHBoxLayout();
hBox->addStretch();
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
auto label = new QLabel(tr("Specify IP"));
label->setAlignment(Qt::AlignCenter);
hBox->addWidget(label);
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
auto fdIP = new QIPLineEdit();
fdIP->setMinimumWidth(160);
hBox->addWidget(fdIP);
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
hBox->addStretch();
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
vBox->addLayout(hBox);
vBox->addStretch();
2022-01-04 18:11:48 +08:00
2022-08-25 18:37:24 +08:00
hBox = new QHBoxLayout();
hBox->addStretch();
auto bnSearch = new QPushButton(tr("Search"));
hBox->addWidget(bnSearch);
auto btnCancel = new QPushButton(tr("Cancel"));
connect(btnCancel, &QPushButton::clicked, this, &QDialog::reject);
hBox->addWidget(btnCancel);
hBox->addStretch();
vBox->addLayout(hBox);
//绑定信号和槽函数
2022-09-28 18:21:57 +08:00
connect(bnSearch, &QPushButton::clicked, this, [this, fdIP] {
2022-08-25 18:37:24 +08:00
QString strTempIp = fdIP->text();
if(strTempIp=="...") {
QMessageBox::warning(gMainWin, tr("Attention"), tr("Please input IP address!"));
return;
} else if(! isTextValid(strTempIp)) {
QMessageBox::warning(gMainWin, tr("Attention"), tr("Your IP Address is Invalid!"));
return;
}
auto waitingDlg = new WaitingDlg(gMainWin, tr("Search")+" ...");
waitingDlg->show();
auto reply = Tools::netManager().get(reqForJson("http://"+strTempIp+":3000/deviceList?fromDetector=true"));
//在该ip的3000端口get方法deviceList可以一次性获取到局域网中设备列表的详细信息
2022-09-28 18:21:57 +08:00
connect(reply, &QNetworkReply::finished, this, [reply, this, waitingDlg] {
2022-08-25 18:37:24 +08:00
QJsonDocument json;
QString err = parseReplyJson(reply);
if(! err.isEmpty()) {
waitingDlg->close();
QMessageBox::critical(gMainWin, tr("Error"), err);
return;
}
waitingDlg->success();
close();
QStringList keys = json.object().keys();
qDebug()<<"json size"<<keys.size();
2022-09-28 18:21:57 +08:00
for(auto key : keys) gDevicePanel->parseInfo(json[key].toObject(), "");
2022-08-25 18:37:24 +08:00
});
});
2022-01-04 18:11:48 +08:00
}