Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4235421
  • 博文数量: 176
  • 博客积分: 10059
  • 博客等级: 上将
  • 技术积分: 4681
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-24 12:27
文章分类

全部博文(176)

文章存档

2012年(1)

2011年(4)

2010年(14)

2009年(71)

2008年(103)

分类: C/C++

2008-07-11 22:45:48

          By zieckey (http://zieckey.cublog.cn)
          All Rights Reserved

本文介绍的程序是 dev-ezx-0.2.0 开发包中的helloworld程序
dev-ezx-0.2.0工具可以在这里下载:http://lsb.blogdns.com/ezx-devkit

具体请看程序的注释。

helloworld.cpp

/*
 * Hello World demo program for EZX
 * Copyright (C) 2005 Sam Revitch
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * Further, this software is distributed without any warranty that it is
 * free of the rightful claim of any third person regarding infringement
 * or the like. Any license provided herein, whether implied or
 * otherwise, applies only to this software file. Patent licenses, if
 * any, provided herein do not apply to combinations of this program with
 * other software, or any other product whatsoever.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */


#include <stddef.h>
#include <stdio.h>

#include <qwsevent_qws.h>
#include <zapplication.h>
#include <zmainwidget.h>
#include <zmessagebox.h>
#include <ezxutilcst.h>
#include <ezxres.h>
#include <qlabel.h>

class MyWidget : public ZMainWidget
{
    Q_OBJECT
public:
    MyWidget(QWidget *parent)
        : ZMainWidget("My first Moto EZX App", true, parent, NULL, 0) {

        
        UTIL_CST *cp;//Moto 手机界面的下面的任务栏,左边是菜单按钮,右边是退出按钮,中间也是一个按钮

        ZPushButton *wp;
        QPopupMenu *pp;

        lp = new QLabel("Hello, world!\n"
                "Try the menu!",
                this, "main_label");
        setContentWidget(lp);
        lp->show();

        cp = new UTIL_CST(this, "Show Dialog");
        setCSTWidget(cp);
        cp->show();

        wp = cp->getRightBtn();//右边按钮的信号为退出信号

        connect(wp, SIGNAL(clicked()), qApp, SLOT(slotQuickQuit()));

        wp = cp->getMidBtn();//中间按钮也处理一个信号,显示一个MessageBox对话框

        connect(wp, SIGNAL(clicked()), this, SLOT(showDialog()));

        pp = new QPopupMenu(cp, "Pop");
        connect(pp, SIGNAL(activated(int)), this, SLOT(menuSelect(int)));
        m_showdialog_menu_id = pp->insertItem("Show Dialog");
        wp = cp->getLeftBtn();//左边按钮的信号为弹出一个菜单选项

        wp->setPopup(pp);
    }

    virtual ~MyWidget() {
        fprintf(stderr, "Tearing down MyWidget...\n");
    }
    
public:
    int    m_showdialog_menu_id;
    QLabel *lp;

public slots:
    void showDialog(void)
    {
        RES_ICON_Reader ir;
        int ret;

        //返回值为ret,

        //ret=0,表明点击了MessageBox左边按钮;

        //ret=1,表明点击了MessageBox右边按钮

        //利用这个返回值,可以做一些信号的处理工作

        ret = ZMessageBox::information(    //一个MessageBox,带一个图标、一行文字、两个按钮

                this,
                ir.getIcon(RES_ICON_DLG_EMPTY_TRASH),//垃圾站的图标

                QString("Hello, World!"),//显示的信息

                QString("Left on!"),    //左边按钮显示的文字

                QString("Screw it!"));//右边按钮显示的文字

        
        fprintf(stderr, "information() returned %d\n", ret);
        
        if ( 0 == ret )//点击了MessageBox左边按钮

        {
            fprintf(stderr, "Left button clicked!");    
            lp->setText("Left button clicked!\n~~zieckey");//重新设置QLable显示的文字

        }
        else//点击了MessageBox右边按钮

        {
            fprintf(stderr, "Right button clicked!");        
            lp->setText("Right button clicked!\n~~zieckey");
        }
    }

    void menuSelect( int selectIndex ) //菜单栏的选择

    {
        if ( selectIndex == m_showdialog_menu_id )
        {
            showDialog();
        }
    }

};

//这里就不用多解释了,所以的qt程序main函数基本一样

//可以参考:http://blog.chinaunix.net/u/16292/showart_220215.html

int main(int argc, char** argv)
{
    ZApplication app (argc, argv);
    MyWidget *wp = new MyWidget(NULL);
    app.setMainWidget(wp);
    wp->show();
    return app.exec();
}

#include "helloworld.moc"


对应的makefile文件

EZX_BASE=..
XPREFIX=arm-linux-
CXX=$(XPREFIX)g++
CC=$(XPREFIX)gcc
STRIP=$(XPREFIX)strip
CXXFLAGS=-fno-exceptions -fno-rtti -DQWS -Wall -g
MOC=$(EZX_BASE)/moc/moc
INCLUDE=-I$(EZX_BASE)/include/qt -I$(EZX_BASE)/include/ezx
LIBDIRS=-L$(EZX_BASE)/lib -L$(EZX_BASE)/lib/ezx/lib
LIBS=-lezxappbase-xscale-r -lqte-mt-xscale-r -lezxjpeg-xscale-r -lezxnotification-xscale-r
OBJS=helloworld.o
APP=helloworld

all: $(APP)
dist: $(APP).mpkg

helloworld.o: helloworld.cpp helloworld.moc

$(APP).mpkg: $(APP)
    cp $(APP) dist/$(APP)
    $(STRIP) dist/$(APP)/$(APP)
    tar -C dist -cvzf $(APP).mpkg $(APP)

clean:
    rm -f $(OBJS) $(APP) $(APP).mpkg

%.o: %.cpp
    $(CXX) $(CXXFLAGS) $(INCLUDE) -c $<

%.moc: %.cpp
    $(MOC) $< -o $@

$(APP): $(OBJS)
    $(CXX) $^ -o $@ $(LIBDIRS) $(LIBS)

阅读(2720) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~