forked from zhengtianzuo/QtOtherExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQtLocalIP.cpp
More file actions
44 lines (40 loc) · 873 Bytes
/
QtLocalIP.cpp
File metadata and controls
44 lines (40 loc) · 873 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*!
*@file QtLocalIP.cpp
*@brief 获取本地IP
*@version 1.0
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
*@author zhengtianzuo
*/
#include "QtLocalIP.h"
#include "ui_QtLocalIP.h"
#include <QHostAddress>
#include <QNetworkInterface>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
getLocalIP();
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::getLocalIP()
{
QList<QHostAddress> list = QNetworkInterface::allAddresses();
foreach (QHostAddress address, list)
{
if(address.protocol() == QAbstractSocket::IPv4Protocol)
{
if (address.toString().contains("127.0."))
{
continue;
}
else
{
ui->listWidget->addItem(address.toString());
}
}
}
}