Chapter 3. Basics

Table of Contents

This chapter will introduce some of the most important aspects of maemomm coding. These will be demonstrated with simple working example code. However, this is just a taster, so you need to look at the other chapters for more substantial information.

Your existing knowledge of C++ will help you with maemomm as it would with any library. Unless stated otherwise, you can expect maemomm classes to behave like any other C++ class, and you can expect to use your existing C++ techniques with maemomm classes. maemomm also conforms to conventions used in gtkmm.

gtkmm basics

You should probably read the Basics chapter in the gtkmm book, but here is a brief summary of the basic techniques you will use with gtkmm


gtkmm applications consist of windows containing widgets, such as buttons and text boxes. In some other systems, widgets are called controls. For each widget in your application's windows, there is a C++ object in your application's code.

Widgets are arranged inside container widgets such as frames and notebooks. Some widgets, such as Gtk::VBox, are not visible - they exist only to arrange other widgets.

Although gtkmm widget instances have lifetimes and scopes just like those of other C++ classes, gtkmm has an optional time-saving feature. Gtk::manage() allows you to say that a child widget is owned by the container into which you place it.


gtkmm, like most GUI toolkits, is event-driven. When an event occurs, such as the press of a mouse button, the appropriate signal will be emitted by the widget that was pressed. To handle a signal, connect a signal handler to catch the signal. For instance

m_button1.signal_clicked().connect( sigc::mem_fun(*this, &HelloWorld::on_button_clicked) );


gtkmm uses Glib::ustring instead of std::string, to support Unicode in UTF-8 encoding. It provides almost the same interface as std::string, along with automatic conversions to and from std::string.

Intermediate types

Some parts of the gtkmm API use intermediate data containers, such as Glib::StringArrayHandle instead of a specific Standard C++ container such as std::vector or std::list. You should not declare these types yourself -- you should use whatever Standard C++ container you prefer instead. gtkmm will do the conversion for you.

Mixing C and C++ APIs

You can use C APIs which do not yet have convenient C++ interfaces. It is generally not a problem to use C APIs from C++, and gtkmm helps by providing access to the underlying C object, and providing an easy way to create a C++ wrapper object from a C object, provided that the C API is also based on the GObject system.

To use a gtkmm instance with a C function that requires a C GObject instance, use the gobj() function to obtain a pointer to the underlying GObject instance. For instance

Gtk::Button* button = new Gtk::Button("example");

To obtain a gtkmm instance from a C GObject instance, use the Glib::wrap() function. For instance

GtkButton* cbutton = get_a_button();
GtkButton* button = Glib::wrap(cbutton);