|
|
|
Home > Computing > Linux > Archos PMA430 (and other Archos AV) stuff > My first Qtopia application
My first Qtopia application -- how to get started with Qtopia development -- part 3
Last modified: Fri Aug 3 08:41:09 2007
A simple graphical program
If you've got this far, it's time to try `Hello, World!' with a Qtopia
interface. Here is the source code, which I will assume is saved in
a file called hello2.cpp.
#include <qmainwindow.h>
#include <qpe/qpeapplication.h>
int main(int argc, char** argv)
{
QPEApplication app(argc, argv);
QMainWindow* mainWindow = new QMainWindow();
mainWindow->setCaption("Hello, World!");
app.showMainWidget(mainWindow);
return app.exec();
}
The first line creates an object of class QPEApplication.
This class models a complete application, and contains the logic for
event handling, and starting up and shutting down, among other things.
We then create a main window for the application. The class
QMainWindow models a main window, that is, one that can have
a menu bar, tool bars, and a frame with a caption. The method call
setCaption() applied to the main window... well, if you've
followed it this far, you can probably guess what it does.
Then we set the newly-created window to be the main `widget'
(user interface element) for the application. Finally, we
use the exec() method to run the application.
The exec() method does not return until the application is
shut down, either because the code calls a method to shut it down,
or the user takes an action to shut it down (such as clicking the
close icon in the frame).
Here's how to compile and link this simple application. First, to
compile:
/opt/Embedix/tools/bin/arm-linux-g++ \
-I /opt/Qtopia/sharp/include/ \
-DQWS -fno-rtti -o hello2.o -c hello2.cpp
The backslash characters indicate continuation on the following line -- you
can type this command in a single line, but I can't write it here in a
single line as it won't fit on the page.
The -I switch tells the compiler to look for header files in
/opt/Qtopia/sharp/include. `sharp' here refers to the Sharp
Zaurus, but the Zaurus Linux distribution is sufficiently similar to
the PMA's that we can use the same headers (lacking a specific set of
headers for the PMA). This -I switch is necessary for the compiler
to be able to find qpeapplication.h, for example.
-DQWS indicates to the Qt headers that we're compiling
for Qtopia. -fno-rtti tells the compiler not to include
run-time type information in the compiled classes. Since the Qtopia
classes are compiled without RTTI, including RTTI in our code will
confuse the linker later.
To link the application, we need:
/opt/Embedix/tools/bin/arm-linux-g++ \
-L /opt/Qtopia/sharp/lib/ -o hello2 hello2.o \
-lqte -lqpe -ljpeg -luuid
The -L switch tells the linker where to look for the libraries which
are specified later. These libraries are:
- -lqte: contains Qt-embedded classes, such as
QMainWwindow
- -lqpe: contains Qtopia application classes, such as
QPEApplication
- -ljpeg: contains code for decoding JPEG images
- -luuid: contains code for generating unique ID numbers
Although we haven't used any code from the JPEG or UUID libraries, the
classes defined in the Qtopia and Qt-embedded libraries are capable of
calling this code, so you won't get a proper link if these libraries
are not included. By default, when you specify a library using `-l',
you get a dynamic link, so specifying these libraries (or even every
library on the device) does not increase the size of the application
significantly.
If the link is successful, you should get an executable hello2,
which you can strip, copy to the PMA, and test as described in the
previous section. When you run this executable, you should get a blank
window on the screen, which you can close by clicking the close icon
in the frame. Good, isn't it?
Go to part 4...
|
|
|
|
Shameless plug
|
 By the author of this site. Buy on-line from Amazon USA | UK
|
|