-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathntpdialog.cpp
More file actions
38 lines (33 loc) · 1.02 KB
/
Copy pathntpdialog.cpp
File metadata and controls
38 lines (33 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "ntpdialog.h"
#include "ui_ntpdialog.h"
NTPDialog::NTPDialog(QWidget *parent, QListWidgetItem *item)
: QDialog(parent)
, ui(new Ui::NTPDialog)
{
ui->setupUi(this);
udpSocket = new QUdpSocket(this);
if(item != nullptr)
ui->lineEdit->setText(item->text());
}
NTPDialog::~NTPDialog()
{
delete ui;
}
void NTPDialog::accept()
{
QHostInfo::lookupHost(ui->lineEdit->text(), this, [=](const QHostInfo &info)
{
QByteArray request(48, 0);
request[0] = 0x1B; //NTPs请求头
if (!info.addresses().isEmpty())
{
settings.setValue("NTPLink", ui->lineEdit->text());
QMessageBox::information(this, tr("Success"), tr("%1\nOutput successful! Saved successfully.").arg(ui->lineEdit->text()));
}
else
{
udpSocket->deleteLater();
QMessageBox::critical(this, tr("Critical"), tr("Output failed! Please try again later or use a different address."));
}
});
}