QNetworkInterface Class
The QNetworkInterface class lists the host's network interfaces and their addresses. More…
| Header | #include <QNetworkInterface> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Network) |
| Module | Nt Network C++ Classes |
List of all members, including inherited members
Public Types
| enum | InterfaceFlag |
| typedef | InterfaceFlags |
| enum | InterfaceType |
Public Functions
| QNetworkInterface() | |
| bool | isValid() const |
| int | index() const |
| int | maximumTransmissionUnit() const |
| QString | name() const |
| QString | humanReadableName() const |
| InterfaceFlags | flags() const |
| InterfaceType | type() const |
| QString | hardwareAddress() const |
| QList<QNetworkAddressEntry> | addressEntries() const |
Static Public Members
| int | interfaceIndexFromName(const QString &name) |
| QNetworkInterface | interfaceFromName(const QString &name) |
| QNetworkInterface | interfaceFromIndex(int index) |
| QString | interfaceNameFromIndex(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.
| Constant | Description |
|---|---|
QNetworkInterface::IsUp | The interface is administratively up. |
QNetworkInterface::IsRunning | The interface has resources allocated and is operational. |
QNetworkInterface::CanBroadcast | The interface works in broadcast mode. |
QNetworkInterface::IsLoopBack | The interface is a loopback interface. |
QNetworkInterface::IsPointToPoint | The interface is a point-to-point link. |
QNetworkInterface::CanMulticast | The 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.
| Constant | Description |
|---|---|
QNetworkInterface::Unknown | The type could not be determined. |
QNetworkInterface::Loopback | A loopback interface. |
QNetworkInterface::Virtual | A virtual interface. |
QNetworkInterface::Ethernet | A wired Ethernet interface. |
QNetworkInterface::Wifi | A wireless interface. |
QNetworkInterface::Ppp | A 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.
QList<QHostAddress> QNetworkInterface::allAddresses()
Returns the IP addresses of every interface on the host.
See also allInterfaces().
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.
QNetworkInterface QNetworkInterface::interfaceFromIndex(int index)
Returns the interface with the given index, or an invalid object if there is none.
See also interfaceFromName().
QNetworkInterface QNetworkInterface::interfaceFromName(const QString &name)
Returns the interface called name, or an invalid object if there is none.
See also interfaceFromIndex().
int QNetworkInterface::interfaceIndexFromName(const QString &name)
Returns the index of the interface called name, or 0 if there is none.
See also interfaceNameFromIndex().
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.