自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何使用 Qt 獲得主機(jī)IP地址及接口 詳細(xì)介紹

移動(dòng)開(kāi)發(fā)
本文介紹的是如何使用 Qt 獲得主機(jī)IP地址及接口,關(guān)于QT網(wǎng)絡(luò)請(qǐng)關(guān)注本文末尾,有更多資料可以供你參考。

如何使用 Qt 獲得主機(jī)IP地址接口是本文介紹的內(nèi)容,不多說(shuō),先來(lái)看內(nèi)容。QNetworkInterface類提供了一個(gè)主機(jī)IP地址和網(wǎng)絡(luò)接口的列表。

QNetworkInterface提供了一個(gè)依附于主機(jī)的網(wǎng)絡(luò)接口,程序可以在上面運(yùn)行。每個(gè)網(wǎng)絡(luò)接口包括0~n個(gè)IP地址,每個(gè)都可選的配有網(wǎng)絡(luò)掩碼或廣播地址。

前提條件---下載安裝***版的Qt for Symbian - Installation packages

傳統(tǒng)函數(shù)返回host機(jī)器上所有的ip地址

  1. QNetworkInterface *inter=new QNetWorkInterface();  
  2. inter->allAddresses(); 

返回host機(jī)器上發(fā)現(xiàn)的所有網(wǎng)絡(luò)接口的列表

  1. QNetworkInterface *inter=new QNetWorkInterface();  
  2. inter->allInterfaces(); 

頭文件 #ifndef NET_H

  1. #define NET_H  
  2. #include <QtGui/QWidget> 
  3. #include<QNetworkInterface> 
  4. #include<QList> 
  5. #include<QLabel> 
  6. #include<QHBoxLayout> 
  7. #include<QString> 
  8. #include<QHostAddress> 
  9. #include<QListWidget> 
  10. namespace Ui  
  11. {  
  12. class netClass;  
  13. }  
  14. class net : public QWidget  
  15. {  
  16. Q_OBJECT  
  17. public:  
  18. net(QWidget *parent = 0);  
  19. ~net();  
  20. private:  
  21. QNetworkInterface *inter;  
  22. QLabel *lbl;  
  23. QHBoxLayout *lay;  
  24. QListWidget *item;  
  25. };  
  26. #endif // NET_H 

源文件 #include "net.h"

  1. #include "ui_net.h"  
  2.    
  3. net::net(QWidget *parent)  
  4. : QWidget(parent)  
  5. {  
  6. QList<QHostAddress> list;  
  7. lbl=new QLabel(this);  
  8. lay=new QHBoxLayout(this);  
  9. item=new QListWidget(this);  
  10. inter=new QNetworkInterface();  
  11. list=inter->allAddresses();  
  12. QString str;  
  13. for (int i = 0; i < list.size(); ++i) {  
  14.    
  15. str = list.at(i).toString();  
  16. item->addItem(str);  
  17. }  
  18. lay->addWidget(item);  
  19. setLayout(lay);  
  20. }  
  21. net::~net()  
  22. {  
  23. // No need to delete any object that got a parent that is properly deleted.  
  24. delete inter;  

獲得網(wǎng)絡(luò)接口的代碼 #include "net.h"

  1. #include "ui_net.h"  
  2. net::net(QWidget *parent)  
  3. : QWidget(parent)  
  4. {  
  5. QList<QNetworkInterface> list;  
  6. lbl=new QLabel(this);  
  7. lay=new QHBoxLayout(this);  
  8. item=new QListWidget(this);  
  9. inter=new QNetworkInterface();  
  10. list=inter->allInterfaces();  
  11. QString str;  
  12. for (int i = 0; i < list.size(); ++i) {  
  13. str = list.at(i).name();  
  14. item->addItem(str);  
  15. }  
  16. lay->addWidget(item);  
  17. setLayout(lay);  
  18. }  
  19. net::~net()  
  20. {  
  21. delete inter;  

顯示host IP  

如何使用 Qt 獲得主機(jī)IP地址及接口 詳細(xì)介紹

顯示網(wǎng)絡(luò)接口     

如何使用 Qt 獲得主機(jī)IP地址及接口 詳細(xì)介紹

小結(jié):如何使用 Qt 獲得主機(jī)IP地址接口 詳細(xì)介紹到這里就介紹完了,希望本文對(duì)你有所幫助!關(guān)于網(wǎng)絡(luò)的更多內(nèi)容,請(qǐng)參考編輯推薦。

責(zé)任編輯:zhaolei 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-06-27 09:36:58

Ubuntu Qt Creator

2011-08-29 10:22:48

QtWebkit 模塊HTML文檔

2011-06-22 17:09:50

QT 進(jìn)程 通信

2011-06-29 15:02:25

Qt 模板庫(kù)

2010-06-02 09:01:20

Linux core

2011-06-29 14:56:28

Qt Creator 快捷捷

2016-12-08 12:47:05

Linux在線主機(jī)IP地址

2011-07-11 16:55:31

Java

2011-07-22 16:37:01

java接口

2022-08-18 23:20:03

數(shù)據(jù)泄露IP 地址隱私

2023-02-01 09:15:41

2011-06-22 13:27:04

QT QMap

2015-07-10 09:08:52

IP地址IP地址沖突

2011-06-23 09:00:04

QT QODBC 數(shù)據(jù)庫(kù)

2023-11-16 09:01:37

Hadoop數(shù)據(jù)庫(kù)

2012-11-27 12:02:20

路由器IPARP

2012-12-10 09:24:04

2009-06-04 20:41:27

Eclipse插件介紹Eclipse插件下載

2010-09-27 13:51:23

接口IP地址故障

2009-09-18 19:21:17

C#接口
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)