'qapplicationapp'在此作用域中尚未声明 linux,安装Qt4 - [软件与系统]

去年春天我用Qt3写了一个小软件,感觉Linux下用Qt作界面程序很方便,和Windows下的VC差不多. 所以上次ubuntu 7.10系统一安装好就将Qt3开发包安装上去。这儿顺便把以前安装Qt3软件包貼出来。

#sudo apt-get install qt3-dev-tools qt3-examples python-qt3 qt3-designer qt3-assistant

现在Qt 的版本已经到Qt-4.3.2了,最近打算用Qt4写个小程序。网上找到安装如下软件包:

#sudo apt-get install qt4-dev-tools qt3-examples qt4-designer qt3-assistant python-qt4

这里面qt3-examples qt3-assistant,因为相应的qt4版本apt-get找不到,所以就安装了以前的版本. 下面写一个Qt4 的hello world, 来源于 C++ GUI Programming with Qt 4的第一个程序,如下:

#include

#include

int main(int argc, char *argv[])

{

QApplication app(argc, argv);

QLabel *label = new QLabel("Hello Qt!");

label->show();

return app.exec();

}

可以发现这个简单的hello world和Qt3就有一些变化了。

下面编译程序:

#qmake -project

生成配置文件xxx.pro(其中xxx为工程文件名)

#qmake

自动生成Makefile文件

#make

出现了下面的错误信息:

me.cpp:1:28: 错误: qt4/QApplication:No such file or directory

me.cpp:2:22: 错误: qt4/QLabel:No such file or directory

me.cpp: In function ‘int main(int, char**)’:

me.cpp:5: 错误: ‘QApplication’ 在此作用域中尚未声明

me.cpp:5: 错误: expected `;' before ‘app’

me.cpp:6: 错误: ‘QLabel’ 在此作用域中尚未声明

me.cpp:6: 错误: ‘label’ 在此作用域中尚未声明

me.cpp:6: 错误: expected type-specifier before ‘QLabel’

me.cpp:6: 错误: expected `;' before ‘QLabel’

me.cpp:8: 错误: ‘app’ 在此作用域中尚未声明

me.cpp: At global scope:

me.cpp:3: 警告: 未使用的参数 ‘argc’

me.cpp:3: 警告: 未使用的参数 ‘argv’

make: *** [me.o] 错误 1

打开Makefile文件, 发现里面包含的Qt文件全部是和 Qt3有关的,使用qmake -v 命令发现果然qmake的版本是3,whereis找到qmake命令所在目录/usr/bin/qmake

#ls -l qmake*

lrwxrwxrwx 1 root root 23 2008-01-18 20:53 /usr/bin/qmake -> /etc/alternatives/qmake

-rwxr-xr-x 1 root root 2052100 2007-10-31 01:29 /usr/bin/qmake-qt3

-rwxr-xr-x 1 root root 3378140 2007-11-06 07:56 /usr/bin/qmake-qt4

# ls -l /etc/alternatives/qmake

lrwxrwxrwx 1 root root 18 2008-01-18 20:56 /etc/alternatives/qmake -> /usr/bin/qmake-qt3

现在清楚了 qmake是个链接,通过alternatives/qmake指向qmake-qt3,现在想让qmake默认为qmake-qt4,只要重定向链接

#sudo rm /etc/alternatives/qmake

#sudo ln -s /usr/bin/qmake-qt4 /etc/alternatives/qmake

同样,想要designer命令默认是版本4,只要

#sudo rm /etc/alternatives/designer

#sudo ln -s /usr/bin/designer-qt4 /etc/alternatives/designer

现在好了,再次qmake -project , qmake, make 上面的hello world文件,一切顺利。

作者: altaitai

发布时间: 2008-04-11

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值