Results 1 to 9 of 9

Thread: How to display My Current System IP Address...???

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2008
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: How to display My Current System IP Address...???

    I have tried many ways and failed to get my system's current IP Address...
    If i use in the following method... i am getting last value present in my ip address..

    Qt Code:
    1. QHostAddress hstAddr;
    2. QMessageBox::information(this,"", " IP Address " + hstAddr.localhost() + "" );
    To copy to clipboard, switch view to plain text mode 
    this is returning my system/host name

    Qt Code:
    1. QMessageBox::information(this,"", " IP Address " + hstAddr.ipv4() + "" );
    To copy to clipboard, switch view to plain text mode 
    this is returning me last digit of my IP Address...
    as for Eg: if my ip address is 198.168.0.2
    its is displaying in the message box the last value 2

    I tried Any also it returned some value...

    So how do i get my IP Address ....

    Thanks in advance...
    Maveric...
    Last edited by jpn; 31st July 2008 at 12:35. Reason: missing [code] tags
    Giving Or Taking Is Both Ways Of Learning.....
    Enjoy...
    Programming

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: How to display My Current System IP Address...???

    Hmm? I don't see such methods as QHostAddress::localhost() or QHostAddress::ipv4() at all.
    J-P Nurmi

  3. #3
    Join Date
    May 2008
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to display My Current System IP Address...???

    I am sorry Sir...
    its been a spelling mistake by me....
    QHostInfo HstInfo;

    QMessageBox::information(this,"", " IP Address " + HstInfo.localHostName() + "" );
    this gives me my Host/System Name...

    similarly how can i get my system IP address like "127.0.0.1"

    thanks in advance....
    Giving Or Taking Is Both Ways Of Learning.....
    Enjoy...
    Programming

  4. #4
    Join Date
    May 2008
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to display My Current System IP Address...???

    Hi all,
    Please help me i am stuck up with this problem....

    I have Used many methods in getting my systems IP Address...
    But failed to get....

    Qt Code:
    1. QHostInfo info;
    2. QString IPAddress;
    3. QHostAddress Address;
    4. QMessageBox::information(this,"","" + info.localHostName() + "");
    5. QMessageBox::information(this,"","IPV4 is ::" + QString::number(Address.toIPv4Address()) + "" );
    6. QMessageBox::information(this,""," Broad Cast Address is ::" + QString::number(Address.Broadcast) + "" );
    7. QMessageBox::information(this,""," Any IP Address is ::" + QString::number(Address.Any) + "" );
    8. QMessageBox::information(this,"","Local Host Address is :: " + QString::number(Address.LocalHost) + "" );
    To copy to clipboard, switch view to plain text mode 
    I am getting all the values but not in the form which i want...
    so can any one help me what to do in getting my systems IP Address..

    Thanks in advance...
    Last edited by maveric; 1st August 2008 at 13:04. Reason: spelling error
    Giving Or Taking Is Both Ways Of Learning.....
    Enjoy...
    Programming

  5. #5
    Join Date
    Apr 2007
    Location
    Ilsfeld, Germany
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 1 Time in 1 Post

    Default Re: How to display My Current System IP Address...???

    Hi,

    try using QHostInfo::addresses

    HTH, Bernd
    --
    Qt Code:
    1. QList <QHostAddress> list = QHostInfo::fromName(QHostInfo::localHostName()).addresses();
    2. for (int i = 0; i < list.size(); i++)
    3. qDebug() << list.at(i).toString();
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2007
    Posts
    63
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to display My Current System IP Address...???

    well m not so sue about the specific QT command but u can use ifcongig to get it.
    I mean direct the out put of ifconfig through system call to a file(system("ifconfig>out))

    n then its very simple to get IP address from file.

  7. #7
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 11 Times in 11 Posts

    Default Re: How to display My Current System IP Address...???

    You need to get the IP adresses from the network interface see

    http://doc.trolltech.com/4.4/qnetworkinterface.html

    You'll find a simple program at the bottom of this thread

    http://www.qtcentre.org/forum/f-qt-p...line-9255.html

    Pete

    p.s. you can use QHostAddress::toString() get the "127.0.0.1" form see

    http://doc.trolltech.com/4.4/qhostaddress.html#toString
    Last edited by pdolbey; 4th August 2008 at 17:29.

Similar Threads

  1. Qt designer plugin errors on OSX Leopard
    By mpotocnik in forum Qt Tools
    Replies: 10
    Last Post: 21st January 2008, 09:45
  2. Replies: 22
    Last Post: 7th December 2007, 09:01
  3. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  4. Replies: 15
    Last Post: 21st April 2007, 17:46
  5. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

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
  •  
Qt is a trademark of The Qt Company.