J.me

Some hello world examples

Here is some hello world example for anyone who interested to develop a native application for ROKR E2. All of the example is very simple and easy to understand as long as you have basic C++ and QT. You can use SDK from lasly or blackhawk, both is working for these application. If you haven’t had cross compiler, then read first here.

The first example is a message dialog like below.

and the source:

#define QT_NO_DRAGANDDROP

#define QT_NO_PROPERTIES

#include <ZApplication.h>

#include <ZMessageDlg.h>

int main(int argc, char **argv)

{

ZApplication* a = new ZApplication(argc, argv);

ZMessageDlg* dlg = new ZMessageDlg(QString(“Hello World!”), QString(“This is hello world application.”), (ZMessageDlg::MessageDlgType)0 , 0 , NULL , “showQ” , true , 0);

a->setMainWidget(dlg);

dlg->show();

a->exec();

return 0;

}

Download example 1

As you can see, we first create instance of ZApplication (we can say that it is QApplication for EZX). Then we create another instance of ZMessageDlg, and followed by usual QT style programming.

Now, lets see another example, the notice dialog:

and the source as below:

#define QT_NO_DRAGANDDROP

#define QT_NO_PROPERTIES

#include <ZApplication.h>

#include <ZNoticeDlg.h>

int main(int argc, char **argv)

{

ZApplication* a = new ZApplication(argc, argv);

ZNoticeDlg* dlg = new ZNoticeDlg((ZNoticeDlg::Type)0, QString(“Hello World!”), QString(“This is hello world application.”), NULL, “showNotify”, true, 0, false);

a->setMainWidget(dlg);

dlg->show();

a->exec();

return 0;

}

Download example 2

Nothing new here, except that we change the ZMessageDlg widget to ZNoticeDlg. You can see the constructor and member of the object on the header file. 🙂

Next, we create our own widget as shown below:

And the source:

#define QT_NO_DRAGANDDROP

#define QT_NO_PROPERTIES

#include <ZApplication.h>

#include <ZKbMainWidget.h>

#include <ZLabel.h>

#include <ZSoftKey.h>

#include <ZScrollPanel.h>

class MyDialog : public ZKbMainWidget

{

Q_OBJECT

public:

MyDialog() : ZKbMainWidget((ZHeader::HEADER_TYPE)3, NULL, “MyDialog”, 0)

{

setMainWidgetTitle(QString(“Hello World!”));

ZSoftKey* softkey = new ZSoftKey(NULL, this, this);

softkey->setText(ZSoftKey::LEFT, QString(“Hi!”), (ZSoftKey::TEXT_PRIORITY)0);

softkey->setText(ZSoftKey::RIGHT, QString(“Quit”), (ZSoftKey::TEXT_PRIORITY)0);

softkey->setClickedSlot(ZSoftKey::RIGHT, qApp, SLOT(quit()));

ZLabel* mainlabel = new ZLabel(QString(“This is hello world application!”), this, “mainlabel”, 0, (ZSkinService::WidgetClsID)4);

mainlabel->setPreferredWidth(240);

mainlabel->setAutoResize(true);

QVBoxLayout* layout = getVBoxLayout();

ZScrollPanel* panel = new ZScrollPanel(this, NULL, 0, (ZSkinService::WidgetClsID)4);

panel->addChild(mainlabel, 10, 50);

layout->addWidget(panel);

setSoftKey(softkey);

}

};

int main(int argc, char **argv)

{

ZApplication* a = new ZApplication(argc, argv);

MyDialog* dlg = new MyDialog();

a->setMainWidget(dlg);

dlg->show();

a->exec();

return 0;

}

#include “hello3.moc”

Here, we create a MyDialog class inheritence from ZKbMainWidget. Inside the class, we have an inherited constructor of ZKbMainWidget. Then inside the constructor, we create instance of ZSoftKey, ZLabel, QVBoxLayout and ZScrollPanel.  I can’t explain line by line though, but I think it is easy to understand. See the source your self and try it, it is the best way to learn. 😉 Oh, and for the last line, we include hello3.moc, this is for generate moc files.

Okay, this is end of this article. See ya!

12 comments | Leave a comment

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.