HelloWorldApp

All this should be done inside an Opie source directory ($OPIEDIR). See the SourceCode section to set one up.

Now it's time to build a demo application:

Write the Application
$ mkdir myhello $ cd myhello $ vi myhello.cpp

''BTW: the $ at each line is the prompt. You don't have to type it. Just in case...''

Type or paste in the following code:

int main( int argc, char **argv ){ QPEApplication a( argc, argv ); QPushButton hello( "Hello world!", 0 ); hello.resize( 100, 30 ); a.setMainWidget( &hello ); hello.show; return a.exec; }
 * 1) include 
 * 2) include 

Create the Project and Make Files
$ vi myhello.pro

type or paste in the following text:

TEMPLATE = app CONFIG += qt warn_on release DESTDIR = $(OPIEDIR)/bin HEADERS = SOURCES = myhello.cpp TARGET = myhello INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe include ( $(OPIEDIR)/include.pro )

Now you need to generate a Makefile. Set,   and. should point to  (where   can be ,  ,  ,  , etc.). NOTE: You need to compile with  for iPAQs. Make sure to either use the build system for that or point  to the right location, e.g.:

export OPIEDIR = YourOpieDir export QTDIR = YourQTDir export QMAKESPEC = $OPIEDIR/mkspecs/qws/linux-arm-g++

Now tell qmake to generate a Makefile with

qmake -o Makefile myhello.pro

qmake gets built when you build Opie. Make sure you use the Opie version or set  yourself ( like x-86-generic )

To integrate your .pro into the buildsystem you've to edit. Add a line like this one

CONFIG_MYHELLO pathto/myhello myhello.pro

Then make it(TM):

make clean-configs make menuconfig; # choose your application make

Note that the build system properly sets,  ,  , and   so you only need to run.

Create an Icon and a Desktop File
Now, create an icon image file. Make sure it's 32x32.

Now, create the desktop file, which Opie will need in order to show your new app on the desktop and let you run it.

Type or paste in the following text:

[Desktop Entry] Comment=Myhello App Exec=myhello Icon=myhello_icon Type=Application Name=Myhello

What We Did
Phew! To review this, you have:


 * Created a project directory for your app
 * Created the project file
 * Created the app's source file
 * Added the app's directory to the global OPIE packages or ran qmake yourself
 * and  in   (or   in your subdir when you've generated the Makefile yourself)
 * Created an icon for your app
 * Created a .desktop file, to make your app available from within the Opie launcher

With any luck, your app will have been successfully built. Make sure there's a file

Install the App
Now, it's time to install. We need to copy the binary, the icon and the desktop file to the handheld. You could also create an IPK package but this would be overkill for our little app. See MakeIpk for details on this.

Type at your console:

$ cd .. $ cp bin/myhello root@ipaq:/opt/QtPalmtop/bin $ scp apps/Applications/myhello.desktop root@ipaq:/opt/QtPalmtop/apps/Applications $ scp pics/myhello_icon.png root@ipaq:/opt/QtPalmtop/pics

Substitute the  with the location of your handheld.

At last! We've built a small application, and have installed it to the handheld.

Check that your new app is now visible on the Applications desktop. If it isn't, then restart Opie. If it still doesn't show up, then either you've stuffed up, or I've botched something while adding to this wiki page.

If you see the icon for your app, launch it, and make sure you see the window.

COMMENTS
Q: shouldn't  simplify the job ?

A: it's not necessary to package your first tests, but of course it's better to make packages for real-world applications -- clem, May 20

Q: What if I want to write an application for OPIE but I don't want it to be part of OPIE? Is it necessary to use the source code? Where could I find the libraries and headers for OPIE development?

A: You don't have to commit your code into Opie, or even put it inside Opie source tree, to use this type of set up, and to link your code to Opie include files and libraries! But you can't, for example, use  functions without at least having the corresponding headers and libs, that's why you should check out Opie code in the directory you want (more on Opie code in CvsSource, already created, and SourceCode as soon as it's ported from the old wiki page). -- clem, May 20

I've copied the code here to a file called 'hello.cc' into a directory, let's say $HOME/src/ipaq/hello/ and compiled it using this commands (be sure to have QTDIR and OPIEDIR variables set correctly):

$ arm-linux-g++ -c -L$QTDIR/lib -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -fno-default-inline -DNO_DEBUG -I$OPIEDIR/include -I$QTDIR/include -o hello.o hello.cc

$ arm-linux-g++ -o hello hello.o -L$QTDIR/lib -lqpe -lqte

After running this two commands, an executable file called 'hello' will be created. Just copy that file to your iPAQ and run it!

(I don't know if this is really the best way to do it, but at least it works. :)

-- Rafael Sepúlveda "drs"

Yes it works, but it will be difficult to remember and long to type, especially when  must be called more that 20 times for real applications ;) That's why a .pro, which generates a cool Makefile for you through qmake, is the way to go! -- clem, May 20