首页| 论坛| 消息

标题:【提问】编译出错
作者:gaoyu
日期:2005-12-23 21:28
内容:

我今天才刚刚装的QT,都不是很清楚.
下面是我摘抄的一个程序:
#include
#include
#include
int main(int argc,char **argv)
{
QApplication a(argc,argv);

QWidget mainwindow;
mainwindow.setMinimumSize(200,100);
mainwindow.setMaximumSize(200,100);

QPushButton helloworld("Hello World!",&mainwindow);
helloworld.setGeometry(&mainwindow);
mainwindow.show();
return a.exec();
}
运行以后就出现下面的错误了,请大侠帮帮忙.
(注:RH9,QT版本是从论坛上下的,qt-x11-opensource-src-4.1.0)
# gcc -lqt HelloWorld.cpp
HelloWorld.cpp:1:26: qapplication.h: 没有那个文件或目录
HelloWorld.cpp:2:21: qwidget.h: 没有那个文件或目录
HelloWorld.cpp:3:25: qpushbutton.h: 没有那个文件或目录
HelloWorld.cpp: In function `int main(int, char**)':
HelloWorld.cpp:7: `QApplication' undeclared (first use this function)
HelloWorld.cpp:7: (Each undeclared identifier is reported only once for each
function it appears in.)
HelloWorld.cpp:7: parse error before `(' token
HelloWorld.cpp:9: `QWidget' undeclared (first use this function)
HelloWorld.cpp:10: `mainwindow' undeclared (first use this function)
HelloWorld.cpp:13: `QPushButton' undeclared (first use this function)
HelloWorld.cpp:13: parse error before `(' token
HelloWorld.cpp:14: `helloworld' undeclared (first use this function)
HelloWorld.cpp:16: `a' undeclared (first use this function)


#1 [XChinux 12-23 21:35]
不能这样进行编译的,如果你要自己编译,而不使用qmake工具的话,那你就要把环境变量都设置清楚了,建议你先看看
http://www.qtcn.org/bbs/thread.php?fid=21
这个版块的【摘录】《KDE2/Qt编程金典》系列帖子,从前往后看,看看怎样写Makefile,怎样进行编译。
如果嫌麻烦要简单的话,那你就阅读本版和Qt tools & IDE版中相关的qmake使用的帖子。

关于GCC(在这里,应该使用g++,而不是gcc)怎样使用来编译和链接Qt程序,你还要详细了解一下。
#2 [gaoyu 12-23 21:41]
XChinux,再问一个比较弱的问题,我之前编译了QT好多次都出错了,今天总共编译了将近8个小时才编译通过,我在/usr/local/qt目录下输入designer,可以显示出Qt designer,请问我的QT装上了吗?
谢谢
#3 [sunbo 12-23 21:43]
显然你的编译器找不到头文件,查看系统路径中是否包含了qt头文件所在了路径,如果没有,加上我想就行了
我没用过红帽子,抱歉不知道在rh9中怎么加路径
#4 [gaoyu 12-23 21:44]
我现在几乎是一点都不了解Qt,你能给我些建议吗?比如该看什么书之类的,多谢了
#5 [XChinux 12-23 21:56]
看本版置顶的学习帖子。

<< 1 2 >> (1/2)

回复 发表
主题 版块