Пардон, запостил старую версию. Правильней так:
#include <qhostaddress.h>
#ifdef Q_WS_WIN
#include <winsock2.h>
#endif
#ifdef Q_WS_X11
#include <unistd.h>
#include <netdb.h>
#endif
inline QHostAddress localHostAddress()
{
#ifdef Q_WS_WIN
WSAData wsadata;
if ( WSAStartup( MAKEWORD(2,0), &wsadata ) != 0 ) return QHostAddress();
#endif
char buf[255];
gethostname( buf, 255 );
hostent* he = gethostbyname( buf );
if ( he ) {
Q_UINT32 haddr = htonl( *((Q_UINT32*)he->h_addr_list[0]) );
return QHostAddress( haddr );
}
else return QHostAddress();
}