Hi, I have problem with ip address.
How can i get current ip address on my pc? I tried used this code:
It was returned:
also I used function: QNetworkAddressEntry::ip () , but without results.
So, I wait for yours propositions to solve my problem.
Printable View
Hi, I have problem with ip address.
How can i get current ip address on my pc? I tried used this code:
It was returned:
also I used function: QNetworkAddressEntry::ip () , but without results.
So, I wait for yours propositions to solve my problem.
Hi, nice to have you here. In this forum is a wonderful function: the search engine: Look here for example.
Hi, i saw that topic, Lykurg. First method is for Linux system, whilst second is wrong. I search functions to use for Windows. :)
I wait for more suggestions about my problem.
gives you all addresses on your computer. if you also want bcst and mask use QNetworkAddressEntry with its functions broadcast and netmask.
That's good, but I have next problem. I don't see my general address whilst I see addresses to my router. I don't know how I can solve this problem. Do you have some ideas?
PS. Functions in class QNetworkAddressEntry are useless, because return 0. I don't know why?
There is no such thing as a "main address". There is just a default route that specifies a device to use (on all operating systems). I think one way to find out which your "primary" device is, is to use use a QTcpSocket and have it "connect" to a possibly non-existing address that is not on the local network, then use QAbstractSocket's localAddress() which returns a QHostAddress, which in turn contains the IP of the local interface. After that you can then find ouch wich interface has the said IP by searching through the list of QNetworkInterfaces.
I think there might be a easier way to find out which is your default network interface, but those approaches possibly require a linux/windows shell and are not platform independent.