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.
![]() |
![]() |
![]() |
|
|
|
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.
![]() |
![]() |
![]() |
|
|
|
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++:
[sbox-SDK_ARMEL: ~] > mkdir helloworld-1.0.0
[sbox-SDK_ARMEL: ~] > cd helloworld-1.0.0
#include <hildonmm.h> // it includes most of the C++ maemo/hildon headers #include <iostream> // C++ IO headers #include "mywindow.h" // the header for our windowImplement the application entry point, which is the main() function:
int main(int argc, char *argv[])The main() function will perform the following tasks:
{
// Let's put our source code here!
}
/* Initialize the gtkmm libraries and checks the arguments passed to your application. */
Gtk::Main main_loop(&argc, &argv);
/* Initialize the hildomm libraries. */
Hildon::init();
/* Initialize libosso environment: */
osso_context_t* osso_context = osso_initialize("helloworld", "1.0.0", TRUE, 0);
if(!osso_context)
std::cerr<<"osso_initialize() failed." <<std::endl;
Glib::set_application_name("Hello World");
MyWindow window;
Hildon::Program::get_instance()->add_window(window);
main_loop.run(window);
osso_deinitialize(osso_context);
#include <gtkmm.h> #include <hildonmm.h> class MyWindow : public Hildon::Window { public: MyWindow(); virtual ~MyWindow(); protected: /* 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; };
#include <gtkmm.h> #include <hildonmm.h> #include "mywindow.h"
MyWindow::MyWindow() : m_item_exit("Exit"), m_item_helloworld("Say Hello") { /* Add items to the menu */ m_main.append(m_item_helloworld); m_main.append(m_item_exit); m_main.show_all(); /* Attach the menu object to the application */ set_main_menu(m_main); /* 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 */ show_all(); }
MyWindow::~MyWindow()
{
}
void MyWindow::on_menu_quit() { /* Close the window */ hide(); }
void MyWindow::on_menu_helloworld() { /* Create and show a "Hello World" dialog */ Hildon::Note helloworld_note(Hildon::NOTE_TYPE_INFORMATION, "Hello World!"); helloworld_note.run(); }
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.
After you have successfully created the source and header files and compiled them, launch the gtkmm Hello World application:
[sbox-SDK_X86: ~] > af-sb-init.sh start
[sbox-SDK_X86: ~] > run-standalone.sh ./helloworld
The maemo "Hello World" source code is available here.