6.0.0-rc4Source

QNetworkInterface Class

The QNetworkInterface class lists the host's network interfaces and their addresses. More…

Header#include <QNetworkInterface>
CMaketarget_link_libraries(app PRIVATE Nt::Network)
ModuleNt Network C++ Classes

List of all members, including inherited members

Public Types

Public Functions

QNetworkInterface()
boolisValid() const
intindex() const
intmaximumTransmissionUnit() const
QStringname() const
QStringhumanReadableName() const
InterfaceFlagsflags() const
InterfaceTypetype() const
QStringhardwareAddress() const
QList<QNetworkAddressEntry>addressEntries() const

Static Public Members

intinterfaceIndexFromName(const QString &name)
QNetworkInterfaceinterfaceFromName(const QString &name)
QNetworkInterfaceinterfaceFromIndex(int index)
QStringinterfaceNameFromIndex(int index)
QList<QNetworkInterface>allInterfaces()
QList<QHostAddress>allAddresses()

Detailed Description

allInterfaces() returns every interface, and allAddresses() is a shortcut for the addresses of all of them.

See also QNetworkAddressEntry and QHostAddress.

Differences from Qt

Linux and Zephyr only for now. Interface data is a snapshot taken when the list is requested. Type detection covers loopback, Ethernet, Wi-Fi and PPP.

On Zephyr the list holds the interfaces of the Zephyr network stack, with their index, MTU, hardware address, addresses and IPv4 netmasks. The flags are IsUp and IsRunning, with CanBroadcast and CanMulticast for Ethernet; the type is Ethernet, Wi-Fi or unknown, and no broadcast address is given. See Nt on Zephyr.

Member Type Documentation

enum QNetworkInterface::InterfaceFlag

Describes the state and abilities of an interface.

ConstantDescription
QNetworkInterface::IsUpThe interface is administratively up.
QNetworkInterface::IsRunningThe interface has resources allocated and is operational.
QNetworkInterface::CanBroadcastThe interface works in broadcast mode.
QNetworkInterface::IsLoopBackThe interface is a loopback interface.
QNetworkInterface::IsPointToPointThe interface is a point-to-point link.
QNetworkInterface::CanMulticastThe interface supports multicast.

typedef QNetworkInterface::InterfaceFlags

The InterfaceFlags type is a typedef for QFlags<InterfaceFlag>. It stores an OR combination of InterfaceFlag values.

enum QNetworkInterface::InterfaceType

Describes the link technology of an interface.

ConstantDescription
QNetworkInterface::UnknownThe type could not be determined.
QNetworkInterface::LoopbackA loopback interface.
QNetworkInterface::VirtualA virtual interface.
QNetworkInterface::EthernetA wired Ethernet interface.
QNetworkInterface::WifiA wireless interface.
QNetworkInterface::PppA point-to-point protocol interface.

Member Function Documentation

QNetworkInterface::QNetworkInterface()

Constructs an invalid interface object.

QList<QNetworkAddressEntry> QNetworkInterface::addressEntries() const

Returns the interface's IP addresses.

[static] QList<QHostAddress> QNetworkInterface::allAddresses()

Returns the IP addresses of every interface on the host.

See also allInterfaces().

[static] QList<QNetworkInterface> QNetworkInterface::allInterfaces()

Returns every network interface on the host.

See also allAddresses().

InterfaceFlags QNetworkInterface::flags() const

Returns the interface's state flags.

QString QNetworkInterface::hardwareAddress() const

Returns the hardware address as colon-separated hex, such as 00:1A:2B:3C:4D:5E, or an empty string if there is none.

QString QNetworkInterface::humanReadableName() const

Returns a name for display. On Linux this is the same as name().

int QNetworkInterface::index() const

Returns the system's index for the interface, or 0 if it is unknown.

[static] QNetworkInterface QNetworkInterface::interfaceFromIndex(int index)

Returns the interface with the given index, or an invalid object if there is none.

See also interfaceFromName().

[static] QNetworkInterface QNetworkInterface::interfaceFromName(const QString &name)

Returns the interface called name, or an invalid object if there is none.

See also interfaceFromIndex().

[static] int QNetworkInterface::interfaceIndexFromName(const QString &name)

Returns the index of the interface called name, or 0 if there is none.

See also interfaceNameFromIndex().

[static] QString QNetworkInterface::interfaceNameFromIndex(int index)

Returns the name of the interface with the given index, or an empty string if there is none.

See also interfaceIndexFromName().

bool QNetworkInterface::isValid() const

Returns true if this object describes an existing interface.

int QNetworkInterface::maximumTransmissionUnit() const

Returns the interface's maximum transmission unit in bytes, or 0 if it is unknown.

QString QNetworkInterface::name() const

Returns the interface's name, such as eth0.

See also humanReadableName().

InterfaceType QNetworkInterface::type() const

Returns the interface's link type.