Is there a cross-platform way to get the local IP address (i.e. something that looks like 192.168.1.49
) of the computer using Qt?
I want to make an FTP server for a Symbian phone and I want to show the IP address the FTP client should connect to.
Is there a cross-platform way to get the local IP address (i.e. something that looks like 192.168.1.49
) of the computer using Qt?
I want to make an FTP server for a Symbian phone and I want to show the IP address the FTP client should connect to.
Here is the code I implemented to get: name, IP, netmask and mac address of localhost.
Use QNetworkInterface::allAddresses()
QNetworkInterface returns lots of addresses. you must filter them, to get desirable result:
If you require more information than just IP addresses (like the subnet), you have to iterate over all the interfaces.
I wanted to get
eth1
IP address of my target machine. Answers provided above helped me to get what I wanted: This is how I wrote my function to get me the IP address of the network interface nameeth1
.QNetworkInterface::allAddresses()
will give you the network addresses. You can then filter the results to IPv4 addresses that are not loopback addresses: