Qt 获取IP地址问题

我要获取主机的IP地址,我上网搜了搜写了下面几句话
#include <qhostinfo.h>
#include <qhostaddress.h>


QString str=QHostInfo::localHostName();
QHostInfo info=QHostInfo::fromName(str);
QHostAddress address=info.addresses().first();
str=address.toString();
结果出现了下面的错误:
Makefile:120: warning: overriding commands for target `moc_record.cpp'
Makefile:117: warning: ignoring old commands for target `moc_record.cpp'
g++ -c -pipe -Wall -W -O2 -DNO_DEBUG -I/arm/qt-2.3.x/qt-2.3.2/include -o main.o main.cpp
g++ -c -pipe -Wall -W -O2 -DNO_DEBUG -I/arm/qt-2.3.x/qt-2.3.2/include -o record.o record.cpp
record.cpp:19:23: qhostinfo.h: 没有那个文件或目录
record.cpp: In constructor `Form1::Form1(QWidget*, const char*, bool, unsigned
  int)':
record.cpp:39: error: `QHostInfo' undeclared (first use this function)
record.cpp:39: error: (Each undeclared identifier is reported only once for
  each function it appears in.)
record.cpp:39: error: syntax error before `::' token
record.cpp:42: error: `info' undeclared (first use this function)
make: *** [record.o] Error 1
我的头文件已经加了问什么还有这个错误啊?请高手指点下,分不多了,不好意思

作者: marcomo1986   发布时间: 2011-06-08

可能是要在.pro文件中添加一些东西,比如qt要使用sqlite数据库就必须在.pro文件加上 QT +=sql

作者: haixuelang   发布时间: 2011-06-08