qtopia_Application_hello_PC_ARM

 

qtopia_Application_hello_PC_ARM


==============================================================================================
在PC机上开发应用程序
=============================================================================================
#cd qt_x86

1. 设置环境变量
export QT2DIR=$PWD/qt-2.3.2
export QTDIR=$QT2DIR
export QTEDIR=$PWD/qt-2.3.10-target
export QPEDIR=$PWD/qtopia-2.1.1-target
export TMAKEDIR=$PWD/tmake-1.13
export TMAKEPATH=$TMAKEDIR/lib/qws/linux-generic-g++

export PATH=$QTDIR/bin:$QPEDIR/bin:$TMAKEDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$QPEDIR/lib:$LD_LIBRARY_PATH


2.【编写并编译应用程序】
    (1)【生成一个工程文件(.pro文件)】
使用progen命令(progen程序可在tmake的安装路径下找到)可以生成工程文件
使用progen产生一个名为hello的工程文件,如下:
progen -t app -o hello.pro
    (2)【新建一个窗体】
cd qt-2.3.2/bin
        ./designer
进入QT Designer开发环境。
        
选择New一>Dialog
这时一侯,您的QT Designer中就会出现一个Froml来.现在我们click一下上面的tools中的那个pushbutton,
(标有OK的图标)并且用mouse选择到一定的大小.在这个pushbutton上面用您的mouse double click一下.
我们就可以改变pushbutton的label了.这里我们把pushbutton 1这几个宇,换成Exit,然梭直接按Enter
或者用mouse选择OK也可以。
现在我们看到,那个button中的标签已将变成Exit了.我们这时一侯还需要给这个Exit Button一个signal(        信号)

,这样当您在Exit这个Button上click的时侯.QT才知道如何去处理这个信号.
        我们按一下F3 Cconnect singnal slot)
    然后,在那个Exit Button上面Click一下.这时一侯我们就看到了Edit Connection的Dialog了.在Signal中选       

择clicked,在slot中,先选择toggle()就好了.这时一侯选择OK.我们就算是完成了.如果想看看这个小程序长什么样子.
可以用CTRL+T来看Preview. (see figure 1)
下一步在您的qt_x86中建立一个qt_program的Directory出来.这个Directory将会
作为我们存放文件的地方.现在我们用File一>Save把这个文件存为hello.ui放在
qt_x86/qt_program的目录下.
    (3)【生成Hello窗体类的头文件和实现文件】--使用uic工具
在qt_x86下:
cd qt_program
../qt-2.3.10-target/bin/uic -o hello.h hello.ui
../qt-2.3.10-target/bin/uic -o hello.cpp -impl hello.h hello.ui
    (4)分别在hello.h; hello.cpp里面添加需要的代码,本例子不用添加代码
    (5)编写主函数main.cpp,内容如下:
#include "qwidget.h"
#include "hello.h"
#include <qapplication.h>
                                                                                              
int main(int argc,char **argv)
{
        QApplication app(argc,argv);
                                                                                              
         From1 *hello=new Form1();
        hello->show();
         app.setMainWidget(hello);
        return(app.exec());
}
     (6)编辑工程文件hello. pro文件
到目前为止,为Hello, World例子编写了一个头文件和两个源文件,这3个文件
应该被包括在工程文件中,因此还需要编辑hello. pro文件,加入这
hello. h, hello. cpp, main. cpp这三个文件名。具体定义如下:
/*************************************************************************
**以下是hello. pro文件的内容
*************************************************************************/
TEMPLATE = app
CONFIG   = qt warn_on
HEADERS =hello.h
SOURCES =hello.cpp /
   main.cpp
INTERFACES=
【注意】:一定要将INTERFACES= hello.uic 修改为:INTERFACES=
否则:报错:重定义
=====================================
Makefile:120: warning: overriding commands for target `moc_hello.cpp'
Makefile:117: warning: ignoring old commands for target `moc_hello.cpp'
g++ -o hello hello.o main.o hello.o moc_hello.o moc_hello.o -L/usr/local/arm/qt_x86/qt/lib -lqte
hello.o(.text+0x0): In function `Form1::Form1[not-in-charge](QWidget*, char const*, bool, unsigned)':
: multiple definition of `Form1::Form1[not-in-charge](QWidget*, char const*, bool, unsigned)'
hello.o(.text+0x0): first defined here
hello.o(.text+0x188): In function `Form1::Form1[in-charge](QWidget*, char const*, bool, unsigned)':
: multiple definition of `Form1::Form1[in-charge](QWidget*, char const*, bool, unsigned)'
hello.o(.text+0x188): first defined here
hello.o(.text+0x310): In function `Form1::~Form1 [not-in-charge]()':
: multiple definition of `Form1::~Form1 [not-in-charge]()'
hello.o(.text+0x310): first defined here
hello.o(.text+0x334): In function `Form1::~Form1 [in-charge]()':
: multiple definition of `Form1::~Form1 [in-charge]()'
hello.o(.text+0x334): first defined here
hello.o(.text+0x358): In function `Form1::~Form1 [in-charge deleting]()':
: multiple definition of `Form1::~Form1 [in-charge deleting]()'
hello.o(.text+0x358): first defined here
moc_hello.o(.text+0x0): In function `Form1::className() const':
: multiple definition of `Form1::className() const'
moc_hello.o(.text+0x0): first defined here
moc_hello.o(.data+0x0): multiple definition of `Form1::metaObj'
moc_hello.o(.data+0x0): first defined here
moc_hello.o(.text+0xc): In function `Form1::initMetaObject()':
: multiple definition of `Form1::initMetaObject()'
moc_hello.o(.text+0xc): first defined here
moc_hello.o(.text+0xcc): In function `Form1::staticMetaObject()':
: multiple definition of `Form1::staticMetaObject()'
moc_hello.o(.text+0xcc): first defined here
moc_hello.o(.text+0x74): In function `Form1::tr(char const*)':
: multiple definition of `Form1::tr(char const*)'
moc_hello.o(.text+0x74): first defined here
moc_hello.o(.text+0xa0): In function `Form1::tr(char const*, char const*)':
: multiple definition of `Form1::tr(char const*, char const*)'
moc_hello.o(.text+0xa0): first defined here
collect2: ld returned 1 exit status
make: *** [hello] Error 1

=====================================
     (7)生成Makefile文件
       (i)编译器是根据Makefile文件内容来进行编译的,所以需要生成Makefile文件。
Qt提供的tmake工具可以帮助我们从一个工程文件(. pro文件)中产生Makefile文
件。结合当前例子,要从hello. pro生成一个Makefile文件的做法是:
首先查看环境变量$TMAKEPATH是否指向PC编译器的配置目录,在命令行下输入以下命令
#echo $TMAKEPATH
如果返回的结果的末尾不是。.. /qws/linux-generic-g++的字符串,那您需要把环境变
量$TMAKEPATH所指的目录设置为指向PC编译器的配置目录
【注】:如果不设置好环境变量,则可能会报错:
   tmake error: Template file tmake.conf not found
       (ii)最后:使用tmake生成Makefile文件:
   (a)修改tmake/lib/qws/linux-generic-g++/tmake.conf
   将TMAKE_LINK = gcc 和TMAKE_LINK_SHLIB = gcc
   分别修改成
   TMAKE_LINK = g++和TMAKE_LINK_SHLIB = g++
   (b)#tmake -o Makefile hello.pro
       (iii)对Makefile做修改,如下:
对于设置LIBS=$(SUBLIBS) -L$(QTDIR)/lib -lm -lqte【注】:一定要加上: -lm
    
     (8)编译连接整个工程:
make  
【报错】:
: undefined reference to `operator new(unsigned)'
/usr/local/arm/qt_x86/qt/lib/libqte.so: undefined reference to `operator new[](unsigned)'
/usr/local/arm/qt_x86/qt/lib/libqte.so: undefined reference to `__cxa_pure_virtual'
/usr/local/arm/qt_x86/qt/lib/libqte.so: undefined reference to `operator delete[](void*)'
collect2: ld returned 1 exit status
make: *** [hello] Error 1
【原因】:
原因是Makefile 里的LINK 项应该为g++ 而不是gcc , 修改
tmake/lib/qws/linux-generic-g++/tmake.conf
#vi $TMAKEPATH/tmake.conf
将TMAKE_LINK = gcc 和TMAKE_LINK_SHLIB = gcc
分别修改成
TMAKE_LINK = g++和TMAKE_LINK_SHLIB = g++
#tmake –o Makefile hello.pro
此时查看Makefile 里的LINK 项应该已经为g++
#make
【报错】:
moc_hello.o(.gnu.linkonce.d._ZTV5Form1+0x134): undefined reference to `QWidget::dragEnterEvent(QDragEnterEvent*)'
moc_hello.o(.gnu.linkonce.d._ZTV5Form1+0x138): undefined reference to `QWidget::dragMoveEvent(QDragMoveEvent*)'
moc_hello.o(.gnu.linkonce.d._ZTV5Form1+0x13c): undefined reference to `QWidget::dragLeaveEvent(QDragLeaveEvent*)'
moc_hello.o(.gnu.linkonce.d._ZTV5Form1+0x140): undefined reference to `QWidget::dropEvent(QDropEvent*)'
collect2: ld returned 1 exit status
make: *** [hello] Error 1
【解决方案】:export QTDIR=$PWD/qt-2.3.10-target

      (9)运行应用程序hello
//在qt_x86/下面运行:
#qvfb&           
#./hello –qws //注:另一终端已运行qvfb
      (10)将hello文件拷贝到qt_x86/qtopia/bin目录下面


   3.【制作图标】

      制作一个16 X 16大小的PNG格式的图标文件,将该文件存放在$QPEDIR/pics目录下,命名为:hello_wpb.png

   4. 制作桌面启动器(.desktop)文件
        在$QPEDIR/apps/Applications目录下,建立一个文本文件,在文件中添加以下的内容,
    这些内容指明了应用的名称,图标名等信息,然后将文件更名为xxxx. desktop。例如对hello,
    (可以将一个已有的desktop文件复制一份,做一些修改即可)
    采用了以下启动器文件(hello. desktop):
    [Desktop Entry]
    Comment=A Hello Program
    Exec=hello
    Icon=hello_wpb    //该项和3.3中所制作的图标相对应
    Type=Application
    Name=hello

    5. 运行应用程序
#qvfb&
#qpe


==============================================================================================
将应用程序发布到开发板上
=============================================================================================

cd qt_arm
#mkdir hello
#cp ../qt_x86/hello/*.* hello
#rm -rf *.o
[注意]:删除所有的.o文件,不然会报错:/arm-linux/bin/ld: hello.o: Relocations in generic ELF (EM:

1. 设置环境变量
export QTDIR=$PWD/qt
export QPEDIR=$PWD/qtopia
export TMAKEDIR=$PWD/tmake
export TMAKEPATH=$TMAKEDIR/lib/qws/linux-arm-g++
export PATH=$QTDIR/bin:$QPEDIR/bin:$TMAKEDIR/bin:$PATH
export LD_LIBRARY_PATH=$QTDIR/lib:$QPEDIR/lib:$LD_LIBRARY_PATH

2. 修改tmake 配置文件
vi $ TMAKEDIR/lib/qws/linux-arm-g++/tmake.conf
将其中“TMAKE_LINK= arm-linux-gcc”
“TMAKE_LINK_SHLIB= arm-linux-gcc”
修改为:“TMAKE_LINK= arm-linux-g++”
“TMAKE_LINK_SHLIB= arm-linux-g++”

3. 使用tmake 工具来生成我们需要的makefile,然后make
#cd hello
#../tmake/bin/tmake –o makefile hello.pro  
#make
【注意】:在使用tmake 命令时要加上它的路径;否则报错:bash: tmake: command not found

4. 在我们开发板上的相应目录中运行“./hello -qws”就可以运行程序了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值