Chinaunix首页 | 论坛 | 博客
  • 博客访问: 32822
  • 博文数量: 8
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 112
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-13 13:12
文章分类

全部博文(8)

文章存档

2011年(1)

2010年(1)

2009年(1)

2008年(5)

我的朋友

分类: LINUX

2008-11-17 18:34:28

    QT是目前在linux上使用比较广泛的图形系统,用户经常配合KDE桌面环境来使用,QT只是一套库函数(类库),KDE才是可执行程序,同时KDE为了其他程序方便的对其操作,也提供一套库函数(类库)。

运行环境:

    在PC机上,QT是基于X11图形系统。

在嵌入设备中,只需使用QTEQT Embedded)即可包括PC平台中X11QT库的功能。

目的:

    虽然,现在QT for linux版本已经达到了4.0以上,但是,可以通过对此文的了解,使读者学会在宿主机和目标板上都能成功的搭建QT环境,同时,还对在PDA环境下搭建QT环境的操作了解。

所需环境及工具:

    本项目的系统平台为redhat9.0,这里要注意的是,读者在安装系统时,最好选择全部安装系统,这样可以避免以下搭建环境时出现的一些错误提示。

假如,读者的redhat9.0系统没有全部安装软件的情况下,以下的操作可能会出现错误提示,当出现有错误提示时,在下面提供了解决方法。

QT相关的安装软件包:

(1) tmake-1.13.tar.gz                   (编译工具,如progentmake

(2) qt-embedded-2.3.7.tar.gz (提供了qte的库)

(3) qtopia-free-1.7.0.tar.gz           QTE的桌面环境程序)

(4) qt-x11-2.3.2.tar.gz           (为了生成相应的QT工具,如designerqvfb等)

(5) e2fsprogs-1.35.tar.gz                     (提供以下要使用的uuid的库)

(6) qtopia-free-src-2.2.0.tar.gz     (安装PDA环境时用到的包)

(7) cross-arm-extra.tgz

 

1Tmake 编译包,tmake.1.11.tar.gztmake.1.13.tar.gz版本。

       此包主要生成progen与tmake工具,progen用于生成工程文件,有一程序,由一个C++ headed和两个source file文件组成,就可以用progen –n hello –o hello.pro命令生成hello.pro工程文件;tmake命令可以生成工程的makefile文件。

2QT/Embedded安装包,如qt-embedded-2.3.7.tar.gzqt-embedded-2.3.10-free.tar.gz版本等等。

       此包可以实现交叉开发图形程序。适合于目标板上开发图形程序,即它提供交叉编译环境。

(以下讲解两种安装方法)

3Qt 2.3.2 for X11安装包,如qt-x11-2.3.2.tar.gz

      此类工具用于产生X11开发环境所需要的两个工具.(QT的桌面版本它带有GNU C++编译器和二进制工具) ,此类版本的工具包,适合与在宿主机上开发图形程序,安装完成后会生成一个designer的图形设计器以及qvfb虚拟帧缓冲。

:Qt 2.3.2 for X11功能类似还有QT/windows,它是windows版本的。

 

QT在嵌入式系统开发中的工具:最实用的工具是qmake和Qt designer图形设计器.

qmake 是一个为编译 Qt/Embedded 库和应用而提供的 Makefile 生成器

 

4qtopia-free版本,如qtopia-free-1.7.0.tar.gzqtopia-free-source-2.1.1.tar.gzqtopia-free-src-2.2.0.tar.gz

Qtopia分为PDA版和Phone,PDA版为自由版,Phone为付费版,自由版有1.7.02.2.0/2.1.1,Phone版的2.1.0 Eval2.1.2

 

操作步骤:

安装过程分为2部分:宿主机(PC机上)的安装与目标机的安装(需要安装交叉编译)

 

1)  宿主机上的安装

命令如下:

步骤1home目录下创建一个host文件夹,解压安装包。

[root@localhost root]#mkdir /home/host

[root@localhost root]#cd /home/host

[root@localhost host]#tar zxvf  tmake-1.13.tar.gz

[root@localhost host]#tar zxvf qt-embedded-2.3.7.tar.gz

[root@localhost host]#tar zxvf qtopia-free-1.7.0.tar.gz

[root@localhost host]#tar zxvf qt-x11-2.3.2.tar.gz

[root@localhost host]#mv tmake-1.13 tmake

[root@localhost host]#mv qt-2.3.7 qt

[root@localhost host]#mv qtopia-free-1.7.0 qtopia

[root@localhost host]#mv qt-2.3.2 qt-x11

步骤2编译qt-x11,编译它的目的是为了得到uicmocdesignerqvfb等工具。

命令如下:

[root@localhost host]#cd qt-x11

[root@localhost qt-x11]#export QTDIR=$PWD

[root@localhost qt-x11]#echo yes|./configure -static -no-xft -no-opengl -no-sm

[root@localhost qt-x11]# make -C src/moc

[root@localhost qt-x11]# cp src/moc/moc bin/

[root@localhost qt-x11]# make -C src

注:此处可能会提示错误信息,那是由于你的系统没有安装X窗口系统环境有问题,错误提示信息如下所示:

kernel/qt_x11.h:65:22: X11/Xlib.h: 没有那个文件或目录

kernel/qt_x11.h:71:23: X11/Xutil.h: 没有那个文件或目录

kernel/qt_x11.h:72:21: X11/Xos.h: 没有那个文件或目录

kernel/qt_x11.h:73:23: X11/Xatom.h: 没有那个文件或目录

kernel/qt_x11.h:84:34: X11/extensions/shape.h: 没有那个文件或目录

kernel/qpsprinter.cpp: In member function `USHORT

   QPSPrinterFontTTF::unicode_for_glyph(int)':

kernel/qpsprinter.cpp:3328: warning: `ULONG offset' might be used uninitialized

   in this function

kernel/qpsprinter.cpp: In constructor `QPSPrinterFont::QPSPrinterFont(const

   QFont&, QPSPrinterPrivate*)':

kernel/qpsprinter.cpp:5195: `XGetFontPath' undeclared (first use this function)

kernel/qpsprinter.cpp:5195: (Each undeclared identifier is reported only once

   for each function it appears in.)

kernel/qpsprinter.cpp:5235: `XFreeFontPath' undeclared (first use this

   function)

make: *** [kernel/qpsprinter.o] Error 1

 

解决方法:利用“添加/删除程序”给系统安装X软件开发包

 

接下去的命令:

[root@localhost qt-x11]# make -C tools/designer/

[root@localhost qt-x11]# make -C tools/qvfb

[root@localhost qt-x11]#cp tools/qvfb/qvfb  bin

[root@localhost qt-x11]# strip bin/uic bin/moc bin/designer bin/qvfb

[root@localhost qt-x11]# cd ..

[root@localhost host]# cp qt-x11/bin/* qt/bin/

cp:是否覆盖‘qt/bin/findtr? y

cp:是否覆盖‘qt/bin/qt20fix? y

cp:是否覆盖‘qt/bin/qtrename140? y

[root@localhost host]# rm -rf qt-x11

 

步骤3设置环境变量,编译qt-embedded

命令如下:

[root@localhost host]# export QTDIR=$PWD/qt

[root@localhost host]# export QPEDIR=$PWD/qtopia

[root@localhost host]# export TMAKEDIR=$PWD/tmake

[root@localhost host]# export TMAKEPATH=$TMAKEDIR/lib/qws/linux-generic-g++

[root@localhost host]# export PATH=$QTDIR/bin:$QPEDIR/bin:$TMAKEDIR/bin:$PATH

[root@localhost host]# cd qt

[root@localhost qt]# make clean

注:此命令会提示出错信息,但是这个错误没有关系的,不影响下面的编译。

[root@localhost qt]# cp $QPEDIR/src/qt/qconfig-qpe.h src/tools/

[root@localhost qt]# ./configure -platform linux-generic-g++ -qconfig qpe -depths 16,24

[root@localhost qt]# make -C src

此时,编译完成。

 

步骤4基于qt-embedded编译并运行应用程序。在qt目录下,创建一个hello目录。

命令如下:

#mkdir hello

#cd hello

#vim hello.cpp

内容如下:

#include

#include

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

{

       QApplication app(argc,argv);

       QPushButton hello(“hello world!”,0);

       hello.resize(100,30);

       app.setMainWidget(&hello);

       hello.show();

       return app.exec();

}

#export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH

#progen –n hello –o hello.pro

#tmake –o Makefile hello.pro

#make

#./hello –qws

运行成功时,会出现如图1所示:

 

 

 

1

:运行此命令前,一定要启动qvfb命令。

 

假如出现以下错误:

./hello: error while loading shared libraries: libqte.so.2: cannot open shared object file: No such file or directory

那是因为没有指定库文件路径.

解决方法:

[root@localhost hello]# export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH

 

 

步骤5编译qtopia

[root@localhost hello]# cd $QPEDIR/src

[root@localhost hello]# export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH

[root@localhost hello]# make

 

注:此处会提示以下错误信息:

global1.cpp:39:23: uuid/uuid.h: 没有那个文件或目录

global1.cpp: In static member function `static QUuid Global::generateUuid()':

global1.cpp:188: `::uuid_generate' undeclared (first use here)

make[1]: *** [.obj/linux-generic-g++//global1.o] Error 1

make[1]: Leaving directory `/home/host/qtopia/src/libraries/qtopia1'

make: *** [libraries/qtopia1] Error 2

 

解决方法:

问题一: 找不到 uuid.h

解决: 下载 e2fsprogs-1.35.tar.gz,解压编译,把 e2fsprogs-1.35/lib/uuid 目录拷贝到 qtopia-free-1.7.0/include

步骤1:通过以下地址下载e2fsprogs-1.35.tar.gz

步骤2:解压并进行编译

./configure

Make

 

问题二: 找不到 –luuid

e2fsprogs-1.35/lib/uuid/libuuid.a 文件拷贝到 usr/lib 或者 qtopia-free-1.7.0/lib

 

步骤6执行qpe

[root@localhost src]# cd ..

[root@localhost qtopia]# cd bin/

[root@localhost bin]# ./qpe

 

注:当执行./qpe时,在另一个终端下必须执行./qvfb,否则无法执行。如果显示正常的话,会出现如图2所示:

 

2

步骤7把应用程序helllo,添加到qtopia中。

[root@localhost bin]# cp -rf /home/host/qt/hello/hello ./

把目标文件拷贝到bin目标下。

[root@localhost root]# cp hello.png /home/host/qtopia/pics/    

此处我把hello.png放在root目录下,拷贝到qtopia/pics目录下。

注:hello.png需要读者去找到一个自己想要的图标,并重命名为hello.png

[root@localhost bin]# vim  /home/host/qtopia/apps/Applications/hello.desktop

内容如下所示:

[Desktop Entry]

Comment=An Hello Program

Exec=hello

Icon=hello

Type=Application

Name=HelloWorld

 

Exec:指出的名字必须与应用程序目标文件名一致。

Icon:指出的是应用程序的图标存放的文件夹。

Name:指出了在desktop(桌面)上显示的程序名。

 

步骤8依次在两个端口下,执行./qvfb./qpe –qws,结果如图3所示:

 

 

 

3

附加:

以上步骤8是基于QTE单独编译后再加入到qtopia的,下面对qtopia源码一起编译,只需要稍微修改一下。

1)  将原来的hello目录复制到qtopia/src/application/目录下。2

2)  hello.cpp文件中将

#include

修改成

#include

3) hello.pro文件中将

CONFIG=qt warn_cm release

修改成

CONFIG= qtopia warn_cm release

增加指定生成目标文件的目录项。

4)按照上述的方法生成hello.desktop和复制图标文件,另外hello目录下的其它文件可以删除。

阅读(930) | 评论(1) | 转发(1) |
0

上一篇:没有了

下一篇:linux进入直接字符界面

给主人留下些什么吧!~~

yy2517450802013-11-19 23:19:15

好东西,。。