-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathChooseIP.cpp
More file actions
27 lines (25 loc) · 879 Bytes
/
Copy pathChooseIP.cpp
File metadata and controls
27 lines (25 loc) · 879 Bytes
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
// 用来服务器选择IP的对话框
#include "ChooseIP.h"
ChooseIP::ChooseIP()
{
this->setWindowTitle("请选择一个IP作为服务器的IP");
this->setWindowFlags(Qt::WindowTitleHint | Qt::CustomizeWindowHint);
box = new QComboBox(this);
button = new QPushButton("确定");
layout = new QHBoxLayout(this);
layout->addWidget(box);
layout->addWidget(button);
QList<QHostAddress> addrList = QNetworkInterface::allAddresses();
foreach (QHostAddress addr, addrList) {
QString addrStr = QHostAddress(addr.toIPv4Address()).toString();
if(addrStr == "0.0.0.0" || addrStr == "127.0.0.1")
continue;
box->addItem(addrStr);
}
connect(button, SIGNAL(clicked(bool)), this, SLOT(chooseAddr()));
}
void ChooseIP::chooseAddr()
{
IPstr = box->currentText();
this->close();
}