MADDE/GTK Example
MADDE is currently a technology preview. These instructions are liable to change as development progresses. If some of the components do not work as expected, please add your question to the MADDE talk thread and follow up the discussion. tablets-dev.nokia.com is down, see MADDE#Installation for alternatives. |
Contents |
[edit] Introduction
This example requires a working configuration of MADDE. At least one target has to be installed and set as 'default'. The basic steps to do this are described in this guide.
- start a project in MADDE
- use template-projects for developing
- compile a project in MADDE
- build a package
[edit] Templates
Templates are used in MADDE to simplify the set up of the basic skeleton for a project. The following command shows the list of available templates:
mad pscreate -l
- The command gives following output:
TEMPLATE NAME TYPE DESCRIPTION empty prog Empty project lib_simple lib Simple example for C/C++ libraries qt_lib_simple qtlib Simple example for Qt libraries qt_simple qtprog Simple example for Qt programs simple prog Simple example for C/C++ programs
[edit] Start the project
The goal of this example is to create a simple GTK helloworld application. Therefore we can use the "simple" template out of the list with small modifications. The following command creates a project using the "simple" template and named as "helloworld"
mad pscreate -t simple helloworld
Afterwards the skeleton is created with the following subdirectories:
- src: place for sourcefiles
- debian:configuration files, which are needed to create the package later on
- uis:empty folder for ui files which would be needed with Qt applications
Further it contains a file named "prog.pro", which is a project file, needed to create the Makefile with qmake.
Lets create a small GTK helloworld application hello.c in src directory:
#include <gtk/gtk.h> static void destroy( GtkWidget *widget, gpointer data ) { gtk_main_quit (); } int main( int argc, char *argv[] ) { GtkWidget *window; GtkWidget *label; gtk_init (&argc, &argv); label = gtk_label_new("Hello world"); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL); gtk_container_add (GTK_CONTAINER (window), label); gtk_widget_show (window); gtk_widget_show(label); gtk_main (); return 0; }
[edit] Compile & build
Before we can compile GTK application we have to modify prog.pro file. In prog.pro file edit SOURCES += and HEADERS += lines to contain source files in the project, in our case wee need only following line: SOURCES += hello.c
For GTK applications we want to use pkgconfig to help compiling and linking against correct libraries.
For our example we add following lines: CONFIG += link_pkgconfig and PKGCONFIG += gtk+-2.0
Now we are ready to build our application.
The following steps describe how to compile and build the project.
1. Create the Makefile:
cd helloworld mad qmake
2. Compile the project.
mad make
- Now the executable program helloworld is created in the helloworld/build directory.
3. Create a debian package:
mad dpkg-buildpackage
- This command will build the project and make a debian package called helloworld_0.1_armel.deb. The debian package will be created in the projects' parent directory.
- This page was last modified on 22 April 2010, at 11:56.
- This page has been accessed 8,260 times.