您的位置:首页 > 编程语言 > Qt开发

Hello world on qtopia

2008-10-20 14:32 405 查看
/****************************************************************************
**Forminterfacegeneratedfromreadinguifile'hello.ui'
**
**Created:FriJun2516:29:292004
**by:TheUserInterfaceCompiler(uic)
**
**WARNING!Allchangesmadeinthisfilewillbelost!
****************************************************************************/
#ifndefHELLO_H
#defineHELLO_H

#include<qvariant.h>
#include<qwidget.h>
classQVBoxLayout;
classQHBoxLayout;
classQGridLayout;

classHello:publicQWidget
{
Q_OBJECT

public:
Hello(QWidget*parent=0,constchar*name=0,WFlagsfl=0);
~Hello();
//下面是手动添加的代码

signals:
voidclicked();
protected:
voidmouseReleaseEvent(QMouseEvent*);
voidpaintEvent(QPaintEvent*);
privateslots:
voidanimate();
private:
QStringt;
intb;

};

#endif//HELLO_H
hello.cpp
/******************************************************************************Formimplementationgeneratedfromreadinguifile'hello.ui'****Created:WedJun2318:02:362004**by:TheUserInterfaceCompiler(uic)****WARNING!Allchangesmadeinthisfilewillbelost!****************************************************************************/#include"hello.h"#include<qtopia/qpeapplication.h>#ifdefQWS#include<qtopia/qcopenvelope_qws.h>#endif#include<qtopia/config.h>#include<qtopia/timestring.h>#include<qtopia/alarmserver.h>#include<qtopia/sound.h>#include<qtopia/resource.h>#include<qlayout.h>#include<qvariant.h>#include<qtooltip.h>#include<qwhatsthis.h>#include<qpushbutton.h>#include<qtimer.h>#include<qpainter.h>#include<qpixmap.h>#include<qwhatsthis.h>/**ConstructsaHellowhichisachildof'parent',withthe*name'name'andwidgetflagssetto'f'*/Hello::Hello(QWidget*parent,constchar*name,WFlagsfl):QWidget(parent,name,fl){if(!name)setName("Hello");resize(240,320);setWFlags(fl|Qt::WStyle_ContextHelp);setMinimumSize(QSize(240,320));setMaximumSize(QSize(240,320));setSizeIncrement(QSize(240,320));setBaseSize(QSize(240,320));QPalettepal;QColorGroupcg;cg.setColor(QColorGroup::Foreground,black);cg.setColor(QColorGroup::Button,QColor(192,192,192));cg.setColor(QColorGroup::Light,white);cg.setColor(QColorGroup::Midlight,QColor(223,223,223));cg.setColor(QColorGroup::Dark,QColor(96,96,96));cg.setColor(QColorGroup::Mid,QColor(128,128,128));cg.setColor(QColorGroup::Text,black);cg.setColor(QColorGroup::BrightText,white);cg.setColor(QColorGroup::ButtonText,black);cg.setColor(QColorGroup::Base,white);cg.setColor(QColorGroup::Background,white);cg.setColor(QColorGroup::Shadow,black);cg.setColor(QColorGroup::Highlight,black);cg.setColor(QColorGroup::HighlightedText,white);pal.setActive(cg);cg.setColor(QColorGroup::Foreground,black);cg.setColor(QColorGroup::Button,QColor(192,192,192));cg.setColor(QColorGroup::Light,white);cg.setColor(QColorGroup::Midlight,QColor(220,220,220));cg.setColor(QColorGroup::Dark,QColor(96,96,96));cg.setColor(QColorGroup::Mid,QColor(128,128,128));cg.setColor(QColorGroup::Text,black);cg.setColor(QColorGroup::BrightText,white);cg.setColor(QColorGroup::ButtonText,black);cg.setColor(QColorGroup::Base,white);cg.setColor(QColorGroup::Background,white);cg.setColor(QColorGroup::Shadow,black);cg.setColor(QColorGroup::Highlight,black);cg.setColor(QColorGroup::HighlightedText,white);pal.setInactive(cg);cg.setColor(QColorGroup::Foreground,QColor(128,128,128));cg.setColor(QColorGroup::Button,QColor(192,192,192));cg.setColor(QColorGroup::Light,white);cg.setColor(QColorGroup::Midlight,QColor(220,220,220));cg.setColor(QColorGroup::Dark,QColor(96,96,96));cg.setColor(QColorGroup::Mid,QColor(128,128,128));cg.setColor(QColorGroup::Text,black);cg.setColor(QColorGroup::BrightText,white);cg.setColor(QColorGroup::ButtonText,QColor(128,128,128));cg.setColor(QColorGroup::Base,white);cg.setColor(QColorGroup::Background,white);cg.setColor(QColorGroup::Shadow,black);cg.setColor(QColorGroup::Highlight,black);cg.setColor(QColorGroup::HighlightedText,white);pal.setDisabled(cg);setPalette(pal);QFontf(font());f.setFamily("adobe-helvetica");f.setPointSize(29);f.setBold(TRUE);setFont(f);setCaption(tr(""));//手动添加的代码t="Hello,World";b=0;QTimer*timer=newQTimer(this);connect(timer,SIGNAL(timeout()),SLOT(animate()));timer->start(40);QWhatsThis::add(this,tr("thisishello,worldsample."));}/**Destroystheobjectandfreesanyallocatedresources*/Hello::~Hello(){//noneedtodeletechildwidgets,Qtdoesitallforus}/*Thisprivateslotiscalledeachtimethetimerfires.*///以下是手动添加的代码voidHello::animate(){b=(b+1)&15;repaint(FALSE);}/*HandlesmousebuttonreleaseeventsfortheHellowidget.Weemittheclicked()signalwhenthemouseisreleasedinsidethewidget.*/voidHello::mouseReleaseEvent(QMouseEvent*e){if(rect().contains(e->pos()))emitclicked();}/*HandlespainteventsfortheHellowidget.Flicker-freeupdate.Thetextisfirstdrawninthepixmapandthepixmapisthenblt'edtothescreen.*/voidHello::paintEvent(QPaintEvent*){staticintsin_tbl[16]={0,38,71,92,100,92,71,38,0,-38,-71,-92,-100,-92,-71,-38};if(t.isEmpty())return;//1:Computesomesizes,positionsetc.QFontMetricsfm=fontMetrics();intw=fm.width(t)+20;inth=fm.height()*2;intpmx=width()/2-w/2;intpmy=height()/2-h/2;//2:Createthepixmapandfillitwiththewidget'sbackgroundQPixmappm(w,h);pm.fill(this,pmx,pmy);//3:Paintthepixmap.CoolwaveeffectQPainterp;intx=10;inty=h/2+fm.descent();inti=0;p.begin(&pm);p.setFont(font());while(!t[i].isNull()){inti16=(b+i)&15;p.setPen(QColor((15-i16)*16,255,255,QColor::Hsv));p.drawText(x,y-sin_tbl[i16]*h/800,t.mid(i,1),1);x+=fm.width(t[i]);i++;}p.end();//4:CopythepixmaptotheHellowidgetbitBlt(this,pmx,pmy,&pm);}
main.cpp
//#include<qconfig-qpe.h>//#include"GUcdragonDlg.h"#include"hello.h"#include<qapplication.h>#include<qtopia/qpeapplication.h>/*QTOPIA_ADD_APPLICATION("hello",Hello)QTOPIA_MAIN*//*Theprogramstartshere.ItparsesthecommandlineandbuildsamessagestringtobedisplayedbytheHellowidget.*/#defineQT_NO_WIZARDintmain(intargc,char**argv){QApplicationa(argc,argv);Hellodlg;QObject::connect(&dlg,SIGNAL(clicked()),&a,SLOT(quit()));a.setMainWidget(&dlg);dlg.show();returna.exec();}
1.在qtopia-free-2.2.0下执行命令:sourcesetQpeEnv就可以设置好QPE相关的环境变量,还需要设置exportQMAKESPEC=?/qtopia-free-2.2.0/qtopia/mkspecs/qws/linux-arm-g++2.在上面的hello目录下面依次执行以下命令:qmake-projectqmakemake就可以得到hello的可执行程序了。3.手写hello.pro文件如下
TEMPLATE=appCONFIG+=qtopiaapp#commentthefollowinglinetoenablebuildingtheexampleapplication#asaquicklaunchapplication.#quicklaunchapplicationsneedtobeinstalledbeforetheycanberun,#ButcanbefastertostartrunninginQtopia.#CONFIG-=buildQuicklaunchHEADERS=hello.hSOURCES=main.cpphello.cppINTERFACES=hello.uiTARGET=helloTARGET.path=/home/nfs/s3c2440_recover/qtopia/bindesktop.files=hello.desktopdesktop.path=/home/nfs/s3c2440_recover/qtopia/apps/ApplicationsINSTALLS+=desktoppics.files=Example.pngpics.path=/home/nfs/s3c2440_recover/qtopia/pics/exampleINSTALLS+=pics
并修改main.cpp如下:
#include"hello.h"#include<qapplication.h>#include<qtopia/qpeapplication.h>QTOPIA_ADD_APPLICATION("hello",Hello)QTOPIA_MAIN
然后执行qmakemake则可以生成libhello.so4.编写.desktop文件如下:
[DesktopEntry]comment=AHelloProgramExec=helloIcon=HelloType=ApplicationName=hello
5.将上面生成的可执行文件hello拷贝之开发板的qtopia/bin目录下面,将hello.desktop拷贝到开发板的qtopia/apps/Application/目录下面。并且将来发板上的qtopia/pic/Clock复制一分,重新命名为hello,将里面的clock.png改为hello.png重新起动开发板的qtopia就可以看到application中有了hello程序了。点击可以运行。但是该程序可以拖动,而且点击状态栏中的小图标则报错。6.将上面的libhello.so拷贝到开发板的qtopia/plugins/application/中。重启qtopia,这是就发现hello程序和其他的qtopia应用程序一样了。开启多个任务,点击状态栏中的ello图标则会切换到hello程序。不过有一个问题是,程序的运行与单个儿的hello有些出入。至于这一点可以参考qtopia其它应用程序的源文件。有关.pro文件的编写可以查看qmake的使用手册!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: