Chinaunix首页 | 论坛 | 博客
  • 博客访问: 254305
  • 博文数量: 84
  • 博客积分: 3742
  • 博客等级: 中校
  • 技术积分: 870
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-20 19:38
文章分类

全部博文(84)

文章存档

2012年(6)

2011年(21)

2010年(54)

2009年(3)

分类: 嵌入式

2010-09-28 16:51:49

去年春天我用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文件,一切顺利。
阅读(977) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~