Qtopia Home - Classes - Hierachy - Annotated - Functions - Licenses - Reference

Qtopia - Optimization using the main() function

Introduction

Starting with Qtopia 1.7, it is no longer recommended that the main() function be written explicitly by the programmer. Instead two macros are provided to declare the application entry point:

QTOPIA_ADD_APPLICATION(NAME,IMPLEMENTATION)
QTOPIA_MAIN

QTOPIA_ADD_APPLICATION() generates code to instantiate the main window, where NAME is the application executable name and IMPLEMENTATION is the application window class. Qtopia 2.1.1 and greater adds a QTOPIA_TARGET define that is the value of TARGET from your .pro file. This makes synchronising the "name" and the TARGET trivial.

QTOPIA_MAIN is either the main() implementation or the interface code necessary to make the application a quicklauncher plug-in.

The main.cpp of all applications should be modeled on this example:

#include "mymainwindow.h"
#include <qtopia/qpeapplication.h>

QTOPIA_ADD_APPLICATION(QTOPIA_TARGET, MyMainWindow)
QTOPIA_MAIN

The application window should be implemented in a self-contained way: it should not perform application-level operations such as testing parameters, calling exit(), or calling quit(); all of these are handled by QPEApplication. Your application window should call close() if it needs to explicitly close, and it must be prepared for the possibility that show() will be called again after the close() but before the application window destructor. In other words, implement your application window in a way that it could be used easily from other applications. If you take this approach it will also mean that most of your program can be trivially reused on Qt/X11, Qt/Windows, Qt/Mac, and any other ports of the Qt API.

Enabling Quicklaunching

If quicklaunching is enabled, then all Applications (not settings or games) are built as quicklaucher plug-ins unless they have the following in their .pro file.

CONFIG-=buildQuicklaunch

When building an application as a quicklauncher application plug-in it is important to be careful of symbol collisions. Because the application is compiled as a plug-in to be loaded, it is possible for symbols used in the application to collide with those of the libraries.

For example, if there are two classes of the same name, one in the application and one in the library the application links to, then it is possible that when the application is run as a quicklauncher application the wrong destructor for the class will be called. This can in turn lead to memory corruption.

The script $QPEDIR/scripts/checksymbols has been provided in order to help with the identification of possible symbol conflicts. Make sure QPEDIR is defined and run the script, passing the .so file created for your application as the argument. The script will list possible symbol collision between your application and the Qtopia libraries.


Copyright © 2005 Trolltech Trademarks
Qtopia version 2.2.0