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).
/opt/Embedix/tools/bin/arm-linux-g++ \ -I /opt/Qtopia/sharp/include/ \ -DQWS -fno-rtti -o hello2.o -c hello2.cppThe 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.
/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 -luuidThe -L switch tells the linker where to look for the libraries which are specified later. These libraries are:
QMainWwindow
QPEApplication
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...
©1994-2006 Kevin Boone, all rights reserved