• 13471阅读
  • 5回复

QApplication: No such file or directory错误 [复制链接]

上一主题 下一主题
离线victordinho
 

只看楼主 倒序阅读 楼主  发表于: 2009-12-29
我刚安装了QT4.6.0,设置好了环境变量,打算在codeblocks用qmake编译一个简单的hello world程序,但出现以下错误:
  1. d:\My Documents\new\qtdemo\qtdemo.cpp|1|QApplication: No such file or directory|
  2. d:\My Documents\new\qtdemo\qtdemo.cpp|2|QPushButton: No such file or directory|
  3. d:\My Documents\new\qtdemo\qtdemo.cpp||In function `int main(int, char**)':|
  4. d:\My Documents\new\qtdemo\qtdemo.cpp|6|error: `QApplication' was not declared in this scope|
  5. d:\My Documents\new\qtdemo\qtdemo.cpp|6|error: expected `;' before "app"|
  6. d:\My Documents\new\qtdemo\qtdemo.cpp|7|error: `QPushButton' was not declared in this scope|
  7. d:\My Documents\new\qtdemo\qtdemo.cpp|7|error: expected `;' before "hello"|
  8. d:\My Documents\new\qtdemo\qtdemo.cpp|8|error: `hello' was not declared in this scope|
  9. d:\My Documents\new\qtdemo\qtdemo.cpp|10|error: `app' was not declared in this scope|
  10. d:\My Documents\new\qtdemo\qtdemo.cpp|6|warning: unused variable 'QApplication'|
  11. d:\My Documents\new\qtdemo\qtdemo.cpp|7|warning: unused variable 'QPushButton'|
  12. d:\My Documents\new\qtdemo\qtdemo.cpp|10|warning: unused variable 'app'|
  13. ||=== Build finished: 8 errors, 3 warnings ===|


程序如下,是在书上直接打上去的:
  1. #include <QApplication>
  2. #include <QPushButton>
  3. int main(int argc, char* argv[])
  4. {
  5.     QApplication app(argc, argv);
  6.     QPushButton hello("Hello world!");
  7.     hello.resize(100, 30);
  8.     hello.show();
  9.     return app.exec();
  10. }


另外说说,环境变量那里path、include和lib都设置好的。我只安装了一个版本的QT。另外,我在网上找到了一些方法,好像在include那里加上Qt/之类的方法,都不行。

请问会是什么原因呢?谢谢。
离线wd007

只看该作者 1楼 发表于: 2009-12-29
从程序上看不出来什么。

你是怎样安装Qt的,确认安装无误吗?

“在codeblocks用qmake编译”这个步骤是怎样的。
欢迎访问我的博客,一起学习提高
http://blog.csdn.net/qter_wd007
离线lishaman
只看该作者 2楼 发表于: 2010-01-24
我也遇到同样的问题 怎么解决啊
没有什么不可能,让我们一起开天辟地!
离线wd007

只看该作者 3楼 发表于: 2010-01-24
而且,能确定现在的CB这个版本支持Qt 4.6吗?
欢迎访问我的博客,一起学习提高
http://blog.csdn.net/qter_wd007
离线xphcyh
只看该作者 4楼 发表于: 2010-08-03
需安装LINUX下的qt库文件
http://qt.nokia.com/downloads/linux-x11-cpp
离线xphcyh
只看该作者 5楼 发表于: 2010-08-04
//**************windows xp平台******************
根据C++ GUI Qt4书本步骤,安装qt-sdk-win-opensource-2010.04.exe
运行Qt Creator
打开hello.pro工程
直接运行:run可以得到hello qt!程序,如下图
  
方式二:
通过Qt Command Prompt进入command窗口
打开这个窗口会自动设置使用MinGW编译器编译qt程序时所需的环境变量!
>cd E:\Downloads\qtopia\qt-book\chap01\hello
>qmake –project
>qmake hello.pro
>make
书籍上介绍使用的是make命令,提示“make不是内部或外部命令”
从论坛上得知,使用的是mingw32-make
> mingw32-make
>cd debug
>hello
同样得到以上效果!

//**************Fedora9平台******************
cd /tmp
下载直接运行qt-sdk-linux-x86-opensource-2010.04.bin
tar zxvf qt-everywhere-opensource-src-4.6.3.tar.gz

因为Fedora9预装了qt3 designer 和qt4 designer!
同样进行make之后,发现出现以下问题:
[root@localhost hello-qt]# qmake -project
[root@localhost hello-qt]# qmake hello-qt.pro
[root@localhost hello-qt]# make
g++ -c -pipe -Wall -W -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables  -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -DQT_THREAD_SUPPORT -I/usr/lib/qt-3.3/mkspecs/default -I. -I. -I/usr/lib/qt-3.3/include -o hello.o hello.cpp
hello.cpp:1:24: 错误:QApplication:没有那个文件或目录
hello.cpp:2:18: 错误:QLabel:没有那个文件或目录
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:6: 错误:‘QApplication’在此作用域中尚未声明
hello.cpp:6: 错误:expected `;' before ‘app’
hello.cpp:7: 错误:‘QLabel’在此作用域中尚未声明
hello.cpp:7: 错误:‘label’在此作用域中尚未声明
hello.cpp:7: 错误:expected type-specifier before ‘QLabel’
hello.cpp:7: 错误:expected `;' before ‘QLabel’
hello.cpp:9: 错误:‘app’在此作用域中尚未声明
hello.cpp: At global scope:
hello.cpp:4: 警告:未使用的参数‘argc’
hello.cpp:4: 警告:未使用的参数‘argv’
make: *** [hello.o] 错误 1
[root@localhost hello-qt]# gedit Makefile
发现INCPATH的路径不对,没有QT4的路径
[root@localhost hello-qt]# $PATH
返回来查看PATH的路劲为
bash: /usr/local/arm/4.3.2/bin:/usr/local/arm/4.3.2/bin:/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin: 没有那个文件或目录
没有QT4/bin的路径,即使用的qmake非QT4 Creator的
[root@localhost hello-qt]# export PATH=/usr/local/arm/4.3.2/bin:/usr/local/arm/4.3.2/bin:/usr/lib/qt4/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin
更改后为以上状态;
[root@localhost hello-qt]# $PATH
bash: /usr/local/arm/4.3.2/bin:/usr/local/arm/4.3.2/bin:/usr/lib/qt4/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/root/bin: 没有那个文件或目录
重新编译
[root@localhost hello-qt]# qmake -project
[root@localhost hello-qt]# qmake hello-qt.pro
[root@localhost hello-qt]# make
g++ -c -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -I. -I. -I. -o hello.o hello.cpp
g++  -o hello-qt hello.o     -lQtGui -lQtCore -lpthread
[root@localhost hello-qt]# ./hello-qt
  
可以发现windows与linux平台的窗口界面不同!
快速回复
限100 字节
 
上一个 下一个