Back to Index

Maemo for mobile developers

Creating, building, and running a "Hello World" application

Table of contents

  1. Creating a "Hello World" GUI application
  2. Building the application
  3. Running the application

Creating a "Hello World" GUI application

Before diving into the coding demonstration, have a look at simple "Hello World" applications on both S60 and Windows Mobile 6. This application was created using the Carbide IDE v1.2 and S60 3rd Edition SDK for Symbian OS, supporting Feature Pack 1, for C++. The S60 "Hello World" source code is available here.

  1. When the application is lauched, the title "HelloWorld" is drawn on the top.
  1. If you click "Options", a menu with "Say Hello" and "Exit" options appears.
  1. If you click the "Say Hello" option, you get a "Hello World!" message printed on a dialog. If you click "Exit", the application will stop.

This application was created using the Microsoft Visual Studio 2005 Professional Edition and Windows Mobile 6 SDK Refresh. The "Hello World" source code is available here.

  1. When the application is lauched, the title "Hello World!" is drawn on the top.
  1. If you click "Options", a menu with "Say Hello" and "Exit" options appears.
  1. If you click the "Say Hello" option, you get a "Hello World!" message printed on a dialog. If you click "Exit", the application will stop.

The maemo "Hello World" application will build a similar GUI on maemo. A typical GUI C++ application on Symbian follows a Document/View approach. Since this is not required in maemo, a simple application which does not use this pattern is created.

To create a simple "Hello World" GUI application for maemo using C++:

  1. Create a folder inside your Scratchbox home directory with the following command:
    [sbox-SDK_ARMEL: ~] > mkdir helloworld-1.0.0
  2. Change into the folder you just created:
    [sbox-SDK_ARMEL: ~] > cd helloworld-1.0.0
  3. Create the following three files for the application:
    main.cpp - application entry point
    mywindow.cpp - main window source code
    mywindow.h - main window header file

  4. The main.cpp file contains the entry point for the application. It means that the main() function is implemented here.
    The header files included in this file are:
    #include <hildonmm.h> // it includes most of the C++ maemo/hildon headers
    #include <iostream> // C++ IO headers
    #include "mywindow.h" // the header for our window
    Implement the application entry point, which is the main() function:
    int main(int argc, char *argv[])
    // Let's put our source code here!
    The main() function will perform the following tasks:
    • Create a Gtk::Main object and initialize the gtkmm and hildonmm libraries.
    • /* Initialize the gtkmm libraries and checks the arguments passed to your application. */
      Gtk::Main main_loop(&argc, &argv);

      /* Initialize the hildomm libraries. */

      /* Initialize libosso environment: */
      osso_context_t* osso_context = osso_initialize("helloworld", "1.0.0", TRUE, 0);

      std::cerr<<"osso_initialize() failed." <<std::endl;
    • Set the application name:
    • Glib::set_application_name("Hello World");
    • Create an object for the main window and attach it to the program. Observe that the class MyWindow is the window class created for the example.
    • MyWindow window;
    • Show the window and start the main processing loop. It finishes when the window is closed.
    • Clean the libosso environment:
    • osso_deinitialize(osso_context);
  5. Declare the class and its attributes on the header file "mywindow.h":
    #include <gtkmm.h>
    #include <hildonmm.h>
    class MyWindow : public Hildon::Window
    	virtual ~MyWindow();
            /* Signal handlers */
            virtual void on_menu_quit();
    	virtual void on_menu_helloworld();
    	/* Menu object */
    	Gtk::Menu m_main;
            /* The menu items */
            Gtk::MenuItem m_item_exit;
            Gtk::MenuItem m_item_helloworld;
  6. Next, code the MyWindow class in mywindow.cpp: To implement this class:
    • Include the necessary headers.
      #include <gtkmm.h>
      #include <hildonmm.h>
      #include "mywindow.h"
    • Create the class constructor.
      MyWindow::MyWindow() :
              m_item_helloworld("Say Hello")
              /* Add items to the menu */
              /* Attach the menu object to the application */
              /* Attach the callback functions to the activate signal */
              m_item_exit.signal_activate().connect(sigc::mem_fun(*this, &MyWindow::on_menu_quit));
              m_item_helloworld.signal_activate().connect(sigc::mem_fun(*this, &MyWindow::on_menu_helloworld));
              /* Make all menu widgets visible */
    • Create the class destructor.

    • Code the callback function that is called when the "Exit" item is selected.
      void MyWindow::on_menu_quit()
              /* Close the window */
    • Code the action when the "Say Hello" option is selected.
      void MyWindow::on_menu_helloworld()
              /* Create and show a "Hello World" dialog */
              Hildon::Note helloworld_note(Hildon::NOTE_TYPE_INFORMATION, "Hello World!");

Building the application

After you have written the above source files, you can build your program with gcc using this command:

[sbox-SDK_X86: ~] > g++ main.cpp mywindow.cpp -o helloworld `pkg-config hildonmm --cflags --libs`
Note that you must surround the pkg-config invocation with backquotes. Backquotes cause the shell to execute the command inside them and to use the command's output as part of the command line.

Alternatively, you can use the automake and autoconf tools to build your applications. See Using Autotools build for more information.

Running the application

After you have successfully created the source and header files and compiled them, launch the gtkmm Hello World application:

  1. Start the maemo system:
    [sbox-SDK_X86: ~] > start
  2. Run the application with the "" script to make it get the correct environment variables and theme:
    [sbox-SDK_X86: ~] > ./helloworld
  3. You should now see the following screen. The application name is shown on the top and the application has a main menu.
  4. Press the Hello World drop-down menu. It contains the "Say Hello" and "Exit" options to choose from, as the following image shows:
  5. Click the "Say Hello" option, and as the following image shows, a Hello World message with an "OK" button is displayed. Click the "OK" button and close the application either by choosing the "Exit" option from the drop-down menu or by clicking "X" in the upper right corner.

The maemo "Hello World" source code is available here.

Compiling and moving an application to a device