Results 1 to 7 of 7

Thread: IP address find

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: IP address find

    Using ifconfig as information source makes you dependent on the platform. Probably the gurus will come up with an easier way, but how about opening up a socket with a default address and reading the IP address out of that?

  2. The following user says thank you to Cruz for this useful post:

    kpmsivachand (21st February 2009)

  3. #2
    Join Date
    Jan 2009
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Cool Re: IP address find

    Thank u very much for your replies I got it.

    Finally i got it the ipaddress only by using the QProcess.

    My code was

    Qt Code:
    1. QString prog = "/bin/bash";//shell
    2. QStringList arguments;
    3. arguments << "-c" << "ifconfig eth0 | grep ‘inet ‘ | awk ‘{print $2}’ | sed ’s/addr://’";
    4. QProcess* process = new QProcess(this);
    5. process->start(prog , arguments);
    6. process->waitForFinished();
    7. QString tmp = process->readAll();
    8. qDebug() << tmp;
    To copy to clipboard, switch view to plain text mode 

    Above code will return only the ip address of the local mechine [ etho inet address: ]
    Last edited by kpmsivachand; 21st February 2009 at 17:43.

  4. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: IP address find

    Did you have a look at QHostInfo ??
    This might work for you ..
    Qt Code:
    1. QString ipaddress = QHostInfo::.addresses().first().toString()
    To copy to clipboard, switch view to plain text mode 


Similar Threads

  1. problems installing Qt opensource with msvc2008 support
    By odin1985 in forum Installation and Deployment
    Replies: 6
    Last Post: 24th May 2008, 09:06
  2. GCC can't find QSqlDatabase!!
    By brevleq in forum Qt Programming
    Replies: 5
    Last Post: 29th October 2007, 07:05
  3. Unable to resolve the IP address. ( Qt 3.)
    By joseph in forum Qt Programming
    Replies: 18
    Last Post: 5th July 2007, 12:02
  4. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  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.