Results 1 to 3 of 3

Thread: How to get the IP Address of the local machine in QT?

  1. #1
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    379
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default How to get the IP Address of the local machine in QT?

    How to get the IP Address of the local machine in Qt?

  2. #2
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: How to get the IP Address of the local machine in QT?

    Look at QNetworkInterface documentation. This class has static methods allAddresses() to get available addresses, including localhost and broadcast address.
    ~ We are nothing in this universe ~

  3. #3
    Join Date
    Sep 2017
    Posts
    1
    Platforms
    Windows

    Default Re: How to get the IP Address of the local machine in QT?

    I referred to this site

    I was able to get the required local IP address:

    foreach(const QNetworkInterface &qNetInterface, QNetworkInterface::allInterfaces()) {
    foreach(const QNetworkAddressEntry &qNetInterfaceAddress, qNetInterface.addressEntries()) {
    if (qNetInterfaceAddress.ip().protocol() == QAbstractSocket::IPv4Protocol
    && qNetInterfaceAddress.ip() != QHostAddress(QHostAddress::LocalHost)
    && qNetInterfaceAddress.netmask().toString() != "")
    {
    qDebug() << qNetInterfaceAddress.ip().toString();
    qDebug() << qNetInterfaceAddress.netmask().toString();
    }
    }
    }

Similar Threads

  1. Replies: 7
    Last Post: 19th April 2011, 12:20
  2. Replies: 2
    Last Post: 22nd December 2009, 20:52
  3. serial port same local machine
    By adamatic in forum Qt Programming
    Replies: 7
    Last Post: 3rd February 2009, 07:29
  4. How to get and set local ip in windows xp using QT?
    By longtrue in forum Qt Programming
    Replies: 0
    Last Post: 5th May 2008, 08:55
  5. How to get local IP
    By naresh in forum Qt Programming
    Replies: 11
    Last Post: 17th May 2006, 15:48

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.