Specifications
SHARP CORPORATION
Sharp SL-series Zaurus “Qtopia” Development Start-up Guide
Ver 1.11, February 28, 2003, 32/63
2.7. Event handling: SIGNAL and SLOT
In order for the application to interact with end-users, the application must have an event handling process. The
following sections briefly describe how to handle events, namely known as SIGNAL and SLOT.
2.7.1. Using already-defined SIGNAL and SLOT
The Qt/Embedded, or Qtopia uses a framework so called SIGNAL and SLOT to handle events. The following is
an example of an event handle process that displays a button, and closes the application when the button is
pressed (or tapped).
QPushButton *quitbutton = new QPushButton( "quit" );
connect( quitbutton, SIGNAL(clicked()), qApp, SLOT(quit() );
The first line is the process to create [quitbutton], and the second line is the process to close the application when
the [quitbutton] is pressed.
When the [quitbutton] is clicked, a “clicked” SIGNAL is issued, and the closure process that is set by
quit()
on
qApp
will be executed. The
qApp
is a pointer defined by the Qt that points at
QApplication
object. Because
clicked()
SIGNAL and
quit()
SLOT are already defined by Qt, you simply need to state that in your code.
For the other defined SIGNAL and SLOT, you are encouraged to look up in the Qt reference documentation
provided on the Trolltech websites. You will see
pressed
,
released
,
clicked
,
toggled
,
stateChanged
SIGNALs in the
QButton
class, or
setText
,
setPixmap
, and
setPicture
SLOTs for the
QLabel
class.
2.7.2. Creating your own SLOT
If the already-defined SIGNAL or SLOT cannot quite handle the desired process, you can also create your own
SIGNAL or SLOT. As it is quite rare that you need your own SIGNAL, this document only describes how to create
your own SLOT. If you need to create your own SIGNAL, please refer to the Qt reference documentations.
In order to create your own SLOT, you need to do the following tasks:
• Add SLOT definition to the class definition
• Create the actual SLOT
• Connect SIGNAL and SLOT
• Use “moc” (Meta Object Compiler) to generate a source for the C++ compiler