Chapter 22. Recommended Techniques
Prev |  | Next

## Chapter 22. Recommended Techniques

This section is simply a gathering of wisdom, general style guidelines and hints for creating gtkmm applications.

Use GNU autoconf and automake! They are your friends :) Automake examines C files, determines how they depend on each other, and generates a Makefile so the files can be compiled in the correct order. Autoconf permits automatic configuration of software installation, handling a large number of system quirks to increase portability..

Subclass Widgets to better organise your code. You should probably subclass your main Window at least. Then you can make your child Widgets and signal handlers members of that class.

Create your own signals instead of passing pointers around. Objects can communicate with each other via signals and signal handlers. This is much simpler than objects holding pointers to each other and calling each other's methods. gtkmm's classes uses special versions of Sigc::Signal, but you should use normal sigc::signals, as described in the libsigc++ documentation.

## Application lifetime

Most applications will have only one window, or only one main window. These applications can use the Gtk::Main::run(Gtk::Window&) overload. It shows the window and returns when the window has been hidden. This might happen when the user closes the window, or when your code decides to hide() the window. You can prevent the user from closing the window (for instance, if there are unsaved changes) by overriding Gtk::Window::on_delete_event().

Most of our examples use this technique.

Prev | Up | Next
Custom Widgets | Home | Using a gtkmm widget