Getting Started with Qtopia

From the horse's mouth (Trolltech) come instructions on how to get started writing applications for Qtopia.
Setting Up the Development Environment

We need to set some environmental variables for our KDevelop project. Run KDevelop, and then click on Project→Project Options→Run Options. Add these variables:

Name: QTDIR Value: /opt/Qtopia
Name: QPEDIR Value: /opt/Qtopia
Name PATH Value: /opt/Qtopia/bin:$PATH
Name LD_LIBRARY_PATH Value: /opt/Qtopia/lib:$LD_LIBRARY_PATH

Similarly, add to the Make Options, for desktop development:

Name: QTDIR Value: /opt/Qtopia
Name: QPEDIR Value: /opt/Qtopia
Name PATH Value: /opt/Qtopia/bin:/opt/Qtopia/tmake/bin:$PATH
Name LD_LIBRARY_PATH Value: /opt/Qtopia/lib:$LD_LIBRARY_PATH
Name TMAKEPATH Value:/opt/Qtopia/tmake/lib/qws/linux-generic-g++

Add -lqtopia to the LIBS line in, as Qtopia 1.7 adds a new library.

At this point, you need to generate a Makefile manually, as KDevelop does not use tmake correctly:

# export TMAKEPATH=/opt/Qtopia/tmake/lib/qws/linux-generic-g++
# tmake -o Makefile

Then you can build the project (F8) from within KDevelop. This little glitch will be resolved in newer versions of Qtopia that use qmake to generate Makefiles.

Getting Gritty

Let's add some functionality to skizzy.

Start the Designer 2 application and open skizzybase.ui, and delete the QLabel. Add a QTabWidget with a QComboBox on the first tab, a QListBox on the second tab and a QMultiLineEdit on the third tab, for example (Figure 2).

Figure 2. If you use QLayouts, it allows your application to resize depending on the display resolution or screen rotation.

Save the .ui file.

Open the file skizzy.cpp with KDevelop. You will see our application is derived from skizzyBase:

skizzy::skizzy( QWidget* parent,  const char* name, WFlags fl )
    : skizzyBase( parent, name, fl )

I want to change main.cpp to a better method of constructing the application that was added since the time that the Qtopia templates for KDevelop were created.

We change the usual main() function:

int main( int argc, char ** argv )
    QPEApplication a( argc, argv );
    skizzy mw;
    a.showMainWidget( &mw );
    return a.exec();

to Qtopia's application macro:


This allows us to create a quicklaunch application, which helps speed up startup time, by using the common application constructor that is already in memory.

My application skizzy doesn't do anything yet, so include:

#include <qpe/fontdatabase.h>

Add a private member:

FontDatabase fdb;

and some functions as private slots:

private slots:
void fillCombo();
void comboSelected(const QString &);
void showFont( QListBoxItem *);

We need to add a few lines in skizzy.cpp here for things we will use:

#include <qstringlist.h>
#include <qcombobox.h>
#include <qtabwidget.h>
#include <qlistbox.h>
#include <qmultilineedit.h>
#include <qfont.h>
#include <qfontinfo.h>

#include <qpe/fontdatabase.h>

and then add the implementations, to which we will connect our widgets signals:

This function uses Qtopia's FontDatabase to
fill the combobox with a list of font names.*/
void skizzy::fillCombo()
	QStringList families = fontdb.families();
  	for ( QStringList::Iterator f = families.begin(); f != families.end();++f ) {
      	QString family = *f;
		ComboBox1->insertItem( family);

This gets called when the combobox is selected, and
fills the listbox on the second tab with the name,
style and point size for the family of fonts
selected, and raises it. */
void skizzy::comboSelected(const QString &selectedFont)

 QStringList styles = fdb.styles( selectedFont );
  	for ( QStringList::Iterator s = styles.begin(); s != styles.end();++s ) {
              QString style = *s;
              QValueList<int> smoothies = fdb.smoothSizes( selectedFont, style );
               for ( QValueList<int>::Iterator points = smoothies.begin(); points != smoothies.end(); ++points ) {
                   QString pointSize = selectedFont + " "+ style +" "+QString::number( *points ) + " ";
                  ListBox1 ->insertItem( pointSize);

This shows example text of the selected font in
the QMultiLineWidget on the 3rd tab, and raises it.*/
void skizzy::showFont( QListBoxItem *item)
	QStringList fontItemString = QStringList::split(' ',item->text());
	QString family, style, point;

    family = fontItemString[0];
    style = fontItemString[1];
    point = fontItemString[2];
    bool ok;
    int i_size = point.toInt(&ok,10);

    if (!ok) {
        style += " "+fontItemString[2];
        point = fontItemString[3];
        i_size = point.toInt(&ok,10);

    QFont selectedFont( family);

     if(style.find("Italic",0,TRUE) != -1) {

     if(style.find("Bold",0,TRUE) != -1) {

     if(style.find("Light",0,TRUE) != -1) {

    MultiLineEdit1->setFont( selectedFont);
    MultiLineEdit1->setText( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" ) );
    MultiLineEdit1->setWordWrap( QMultiLineEdit::WidgetWidth);


Qt and Qtopia use signals for sending messages between widgets. Every widget has some kind of signal it emits, and we can use the connect macros to link up functionality.

Connect ComboBox1's activated signal, and ListBox1's clicked signal to our slots, like this:

skizzy::skizzy( QWidget* parent,  const char* name, WFlags fl )
    : skizzyBase( parent, name, fl )
    connect(bye, SIGNAL(clicked()), this, SLOT(goodBye()));
    connect(ComboBox1, SIGNAL(activated(const QString &)), this, SLOT(comboSelected(const QString &)));
    connect(ListBox1, SIGNAL( clicked ( QListBoxItem * )), this, SLOT(showFont( QListBoxItem*)));

Notice how the slot function takes an argument of the exact same type as the signal.

In KDevelop, either press F8, or in the menu, select Build→Build Project.

It should now compile, using the native compiler. To run it, start up QVFb, and simply select Build→Execute Main Program. The skizzy application should show up in QVFb.

Figure 3. Skizzy with real, if not useful features.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

How to install Qtopia core for arm?

Anonymous's picture

I'd be grateful if you could tell me step by step how to install Qtopia for arm. Whether there are any compatible (more importantly incompatible) toolchains for Qtopia core to work. I tried to compile Qtopia core 4.2.2 for arm by giving ./configure -embedded arm, and the make failed. I am using the toolchain with binutils 2.17 and gcc 4.1.1. My native gcc has version 4.0.0
Qtopia core has compiled successfully for my i.386 machine.

Qtopia application deployment

Sakthi's picture

The article is wonderful and it covers the things for beginners...

But we need some more guidelines on 'Deployment of advanced
Qtopia application on target board' because any small application
could be deployed to the target board without any problem..

So we need some more guidelines about the deployment of application
that uses pim library ...developed using Qtopia 1.7 sdk but the
target has qtopia 1.5 ( does not have any pim libraries )