You Are Here:

Community: Wiki

This page was last modified on 6 November 2009, at 08:14.

Getting Host's IP addresses and Interfaces

From Forum Nokia Wiki

Reviewer Approved   



ID ... Creation date 27 June 2009
Platform S60 3rd Edition, S60 5th Edition Tested on devices Qt Creator IDE
Category Qt for Symbian Subcategory


Keywords (APIs, classes, methods, functions): QNetworkInterface


Introduction

The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces.

QNetworkInterface represents one network interface attached to the host where the program is being run. Each network interface may contain zero or more IP addresses, each of which is optionally associated with a netmask and/or a broadcast address.

Preconditions

Functions

  • This convenience function returns all IP addresses found on the host machine.
QNetworkInterface *inter=new QNetWorkInterface();
inter->allAddresses();
  • Returns a listing of all the network interfaces found on the host machine.
QNetworkInterface *inter=new QNetWorkInterface();
inter->allInterfaces();

Source Code

Header File

#ifndef NET_H
#define NET_H
 
#include <QtGui/QWidget>
#include<QNetworkInterface>
#include<QList>
#include<QLabel>
#include<QHBoxLayout>
#include<QString>
#include<QHostAddress>
#include<QListWidget>
namespace Ui
{
class netClass;
}
 
class net : public QWidget
{
Q_OBJECT
 
public:
net(QWidget *parent = 0);
~net();
 
private:
QNetworkInterface *inter;
QLabel *lbl;
QHBoxLayout *lay;
QListWidget *item;
 
};
 
#endif // NET_H

Source File

#include "net.h"
#include "ui_net.h"
 
net::net(QWidget *parent)
: QWidget(parent)
{
QList<QHostAddress> list;
lbl=new QLabel(this);
lay=new QHBoxLayout(this);
item=new QListWidget(this);
inter=new QNetworkInterface(this);
list=inter->allAddresses();
QString str;
for (int i = 0; i < list.size(); ++i) {
 
str = list.at(i).toString();
item->addItem(str);
}
 
lay->addWidget(item);
setLayout(lay);
}
 
net::~net()
{
// No need to delete any object that got a parent that is properly deleted.
 
}

Source File for getting network Interface

#include "net.h"
#include "ui_net.h"
 
net::net(QWidget *parent)
: QWidget(parent)
{
QList<QNetworkInterface> list;
lbl=new QLabel(this);
lay=new QHBoxLayout(this);
item=new QListWidget(this);
inter=new QNetworkInterface(this);
list=inter->allInterfaces();
QString str;
for (int i = 0; i < list.size(); ++i) {
 
str = list.at(i).name();
item->addItem(str);
}
 
lay->addWidget(item);
setLayout(lay);
}
 
net::~net()
{
 
}

Screenshot

  • Showing Host IP's

Image:Network.JPG

  • Showing Network Interface

Image:Interface.JPG

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fHowE5ftoE5fuseE5fE51WidgetE5finE5fE51tE5fforE5fSymbianX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZE71tQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxE71tX qfnZuserE5ftagQSxs60X qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ