Results 1 to 9 of 9

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

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

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

    Hi.. All,

    I am developing an application in which i need to communicate with and transmit data using TCP protocol...
    For that i need IP Address...
    So my question is how to get my Ip address...
    i tried using this....
    QHostAddress ( quint32 ip4Addr ) for getting... Ip address of my system...

    but it returned some linker error...

    These are the linker errors... (which i couldnt debug them...)


    rfswitchmainwindow.obj : error LNK2019: unresolved external symbol "__declspec (dllimport) public: __thiscall QHostAddress::QHostAddress(class QHostAddress const &) " (__imp_??0QHostAddress@@QAE@ABV0@@Z) referenced in function "private: void __thiscall QList<class QHostAddress>::node_copy(struct QList<class QHostAddress>::Node *,struct QList<class QHostAddress>::Node *,struct QList<class QHostAddress>::Node*) " (?node_copy@?$QList@VQHostAddress@@@@AAEXPAUNode@1 @00@Z)

    rfswitchmainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QHostAddress::~QHostAddress(void)" (__imp_??1QHostAddress@@QAE@XZ) referenced in function "public: void * __thiscall QHostAddress::`scalar deleting destructor'(unsigned int)" (??_GQHostAddress@@QAEPAXI@Z)

    fswitchmainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QHostInfo::~QHostInfo(void)" (__imp_??1QHostInfo@@QAE@XZ) referenced in function "private: void __thiscall RFSwitchMainWindow:n_ControlPannel_Button_clicked(void)" (?on_ControlPannel_Button_clicked@RFSwitchMainWind ow@@AAEXXZ)

    rfswitchmainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class QList<class QHostAddress> __thiscall QHostInfo::addresses(void)const " (__imp_?addresses@QHostInfo@@QBE?AV?$QList@VQHostA ddress@@@@XZ) referenced in function "private: void __thiscall RFSwitchMainWindow:n_ControlPannel_Button_clicked(void)" (?on_ControlPannel_Button_clicked@RFSwitchMainWind ow@@AAEXXZ)

    rfswitchmainwindow.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall

    QHostInfo::QHostInfo(int)" (__imp_??0QHostInfo@@QAE@H@Z) referenced in function "private: void __thiscall RFSwitchMainWindow:n_ControlPannel_Button_clicked(void)" (?on_ControlPannel_Button_clicked@RFSwitchMainWind ow@@AAEXXZ)

    so can any one tell me where i am going wrong...?


    Thanks in advance...
    Last edited by jpn; 30th June 2008 at 15:10. Reason: missing [quote] tags

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

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

    Hi,

    Only QtCore and QtGui modules are enabled by default. QHostAddress is part of QtNetwork, which you can take in use by adding the following line in your app's .pro file:
    Qt Code:
    1. QT += network
    To copy to clipboard, switch view to plain text mode 
    Does this solve the problem?
    J-P Nurmi

  3. #3
    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 13:35. Reason: missing [code] tags
    Giving Or Taking Is Both Ways Of Learning.....
    Enjoy...
    Programming

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

    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

  5. #5
    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

  6. #6
    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 14:04. Reason: spelling error
    Giving Or Taking Is Both Ways Of Learning.....
    Enjoy...
    Programming

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

    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 

  8. #8
    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.

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

    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 18:29.

Similar Threads

  1. Qt designer plugin errors on OSX Leopard
    By mpotocnik in forum Qt Tools
    Replies: 10
    Last Post: 21st January 2008, 10:45
  2. Replies: 22
    Last Post: 7th December 2007, 10:01
  3. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 19:59
  4. Replies: 15
    Last Post: 21st April 2007, 18:46
  5. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 23: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.