PDA

View Full Version : How to display My Current System IP Address...???



maveric
30th June 2008, 11:11
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::on_ControlPannel_Button_clicke d(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::on_ControlPannel_Button_clicke d(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::on_ControlPannel_Button_clicke d(void)" (?on_ControlPannel_Button_clicked@RFSwitchMainWind ow@@AAEXXZ)


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


Thanks in advance...

jpn
30th June 2008, 14:17
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 += network
Does this solve the problem?

maveric
31st July 2008, 12:20
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..


QHostAddress hstAddr;
QMessageBox::information(this,"", " IP Address " + hstAddr.localhost() + "" );
this is returning my system/host name


QMessageBox::information(this,"", " IP Address " + hstAddr.ipv4() + "" );
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...

jpn
31st July 2008, 12:39
Hmm? I don't see such methods as QHostAddress::localhost() or QHostAddress::ipv4() at all.

maveric
31st July 2008, 14:22
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....

maveric
1st August 2008, 13:03
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....




QHostInfo info;
QString IPAddress;
QHostAddress Address;
QMessageBox::information(this,"","" + info.localHostName() + "");
QMessageBox::information(this,"","IPV4 is ::" + QString::number(Address.toIPv4Address()) + "" );
QMessageBox::information(this,""," Broad Cast Address is ::" + QString::number(Address.Broadcast) + "" );
QMessageBox::information(this,""," Any IP Address is ::" + QString::number(Address.Any) + "" );
QMessageBox::information(this,"","Local Host Address is :: " + QString::number(Address.LocalHost) + "" );


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

bst
1st August 2008, 14:35
Hi,

try using QHostInfo::addresses

HTH, Bernd
--

QList <QHostAddress> list = QHostInfo::fromName(QHostInfo::localHostName()).ad dresses();
for (int i = 0; i < list.size(); i++)
qDebug() << list.at(i).toString();

raghvendramisra
1st August 2008, 15:42
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.

pdolbey
4th August 2008, 17:22
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-programming-2/t-networking-problems-while-off-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