Repository navigation
Expand file tree
/
Copy pathipaddressdialog.cpp
More file actions
55 lines (45 loc) · 1.77 KB
/
Copy pathipaddressdialog.cpp
File metadata and controls
55 lines (45 loc) · 1.77 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "ipaddressdialog.h"
#include <QSettings>
IpAddressDialog::IpAddressDialog(QWidget *parent)
: QDialog(parent)
{
// Create the line edits
ipEdit = new QLineEdit();
portEdit = new QLineEdit();
// Set input masks
// ipEdit->setInputMask("000.000.000.000;_");
// portEdit->setInputMask("00000;_"); // Optional, restrict to 5 digits
// Load the last entered IP address and port from settings
QSettings settings;
ipEdit->setText(settings.value("lastIpAddress").toString());
portEdit->setText(settings.value("lastPortNumber").toString());
// Create labels
QLabel *ipLabel = new QLabel("IP Address:");
QLabel *portLabel = new QLabel("Port (optional):");
// Create layout
QVBoxLayout *layout = new QVBoxLayout(this);
QHBoxLayout *ipLayout = new QHBoxLayout();
QHBoxLayout *portLayout = new QHBoxLayout();
// Add widgets to layouts
ipLayout->addWidget(ipLabel);
ipLayout->addWidget(ipEdit);
portLayout->addWidget(portLabel);
portLayout->addWidget(portEdit);
// Add layouts to main layout
layout->addLayout(ipLayout);
layout->addLayout(portLayout);
// Add OK and Cancel buttons
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &IpAddressDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &IpAddressDialog::reject);
layout->addWidget(buttonBox);
}
void IpAddressDialog::accept()
{
// Save the entered IP address and port to settings
QSettings settings;
settings.setValue("lastIpAddress", ipEdit->text());
settings.setValue("lastPortNumber", portEdit->text());
// Call the base class implementation of accept
QDialog::accept();
}