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

  1. Kidscracker December 8, 2008 01:43

    helly jeffri, well just to thank you fro the examples, but i have a problem, i generate hello3.moc manually then copile but when i execute it on my e2 it just throw a Segmentation Fault, do you have any solution for it? thanks in advance…nice blog 😉

  2. Kidscracker December 8, 2008 01:56

    Well just to let you knwo that everything was a matter of header , lasly’s sdk seems to have some issues, but blackhawk’s has fixed it.

  3. keaglez December 8, 2008 06:41

    Hmm… I think you were right. I use blackhawk’s SDK to compile too, but when I was on Windows through Cygwin with lasly’s SDK, I happen to get this segmentation fault issue. However, while I move to Linux, I change to blackhawk’s one and it compiles fine. 🙂 Thanks for your visit!

  4. axialis December 13, 2008 12:48

    hi keaglez, i have a question, how can i add a little images in option menu? I mean in your example 3. thanks in advance.

    • keaglez December 13, 2008 12:57

      Yes, you can… You can see the example on my Adv Menu Organizer source. 🙂 The trick is on these lines:

      QString iconpath = “your/images/directory”;
      QPixmap* icon = new QPixmap(iconpath);
      options_instance->insertItem(QString(” Your options menu”), NULL, icon, true, 0, 0);

      I actually get it from SFE source from BlinK_. 😉

  5. axialis December 13, 2008 15:00

    take a look, this works perfect

    QPixmap* pm = new QPixmap();
    pm->load(QString() + “images/about.png”);
    menu->insertItem(QString(” Your options menu”), NULL, pm, true, 2, 2);

    ^^

  6. keaglez December 13, 2008 15:06

    Yeah.. 🙂 it surely works…

  7. axialis December 14, 2008 09:29

    ey keaglez, give me a favor please, can you share with me, your headers ? please ^^

    I mean the ezx headers of course. XD

    thanks in advance.

    • keaglez December 14, 2008 11:45

      Hmm… sure, it is arctu’s header actually… Gimme your email… 🙂 The email you used here seems not working…

  8. axialis December 14, 2008 12:07

    here you go:

    c_plusplus_1@hotmail.com

    thanks.

    • keaglez December 14, 2008 12:24

      okay… sent….

  9. axialis December 16, 2008 14:18

    hi keaglez, thank you for share with me your headers. XD
    ^^

Leave a comment