Chapter 2. Callbacks

Table of Contents

2.1. Types of Callback Functions
2.2. Signals and Slots
2.3. Handlers
2.4. Key Press Counter Example

2.1. Types of Callback Functions

Interface programming is based on callback functions which provide a response to interrupts or events in the underlying system environment. These are processed in qtHaskell via the normal event handling loop mechanisms provided by Qt. In most cases a call to qApplicationExec () or exec someQDialogObject () is all that is needed to start event processing in a qtHaskell program.

The term "callback function" will be used in the following text in the general sense to refer to any Haskell functions which may be passed to the underlying C++ wrapper classes via the Haskell Foreign Function Interface. There are three categories of callback functions that can be specified in qtHaskell programs:

  • Slots. These are activated by Signals in the Qt MetaObject system;

  • Handlers. These correspond to virtual functions in the C++ definition of Qt Classes.

  • User Defined Functions. These are similar to handlers except that they allow the user to create a new virtual function for a class rather than overriding an existing virtual function.

Note that all virtual methods of a Qt class can be overridden by specifying a handler function in qtHaskell even though the method does not correspond to a system event, i.e. the method is only called from the application's own code. This is the case for all User Defined Functions.