How to acquire host IP within program

CrazYmonkeY159

Expert Member
Joined
Sep 13, 2007
Messages
2,142
Reaction score
0
Location
CPT/PE
Hello all.

I am currently working on a mini project for Uni. Ive run into a little problem. Im currently coding a simple tcpserver application

I do not know how to obtain my PC's current IP (Ethernet, assume the PC only has 1 Network interface, if that makes a difference)

something like getting your IP from cmd->"ipconfig /all"

reasons for this being I want the program to display its own IP so that I can enter this IP into connecting clients.

If it matters, im using C++ in Windows using the Qt framework, after some googling it seems as if Qt has no such method of doing what Im looking for, any ideas people? thanks in advance
 
I think the function you're looking for is:

QHostAddress QTcpServer::serverAddress () const
and
QString QHostAddress::toString () const
 

This means "all network interfaces" and although I'm not a QT expert I think that class is used to create a server socket and not for obtaining the PCs IP address. The way I read the documentation, you can construct an instance of this class and it will listen for connection on a particular port and IP address.
 
Top
Sign up to the MyBroadband newsletter
X