• 4809阅读
  • 0回复

qt下helloworld遇到问题的解决方案 [复制链接]

上一主题 下一主题
离线张晋芳
 
只看楼主 倒序阅读 楼主  发表于: 2008-08-29
— 本帖被 XChinux 执行加亮操作(2008-08-29) —
关键词: helloworld
#include <qapplication.h>
#include <qpushbutton.h>
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QPushButton hellobtn( "Hello world!", 0 );
hellobtn.resize(100, 20 );
a.setMainWidget( &hellobtn );
hellobtn.show();
return a.exec();
}
这是代码..
这是我执行hello程序时候出现的问题 
[root@fkw root]# cd /root/qt
[root@fkw qt]# qmake
[root@fkw qt]# make
g++ -c -pipe -Wall -W -O2 -g -pipe -march=i386 -mcpu=i686 -fno-use-cxa-atexit -fno-exceptions -DQT_NO_DEBUG -I/usr/lib/qt-3.1/mkspecs/default -I. -I/usr/lib/qt-3.1/include -I.ui/ -I.moc/ -o .obj/hello.o hello.cpp
hello.cpp:1:24: QApplication: 没有那个文件或目录
hello.cpp:2:23: QPushButton: 没有那个文件或目录
hello.cpp: In function `int main(int, char**)':
hello.cpp:5: error: `QApplication' undeclared (first use this function)
hello.cpp:5: error: (Each undeclared identifier is reported only once for each
function it appears in.)
hello.cpp:5: error: syntax error before `(' token
hello.cpp:6: error: `QPushButton' undeclared (first use this function)
hello.cpp:7: error: `hello' undeclared (first use this function)
hello.cpp:9: error: `app' undeclared (first use this function)
hello.cpp:4: warning: unused parameter `int argc'
hello.cpp:4: warning: unused parameter `char**argv'
解决方法:如果qt安装正确的话,这个问题是由于没有修改环境变量引起的,只要将/usr/local/Trolltech/Qt-4.2.2/bin添加到PATH变量,操作如下:

用vi 打开.bash_profile

在文件的最后一行加上:

PATH=/usr/local/Trolltech/Qt-4.2.2/bin:$PATH

export PATH

保存退出。再次编译就不会出现这个问题啦。

更多学习交流:blog.sina.com.cn/fangandfang
快速回复
限100 字节
 
上一个 下一个