Specifications
SHARP CORPORATION
Sharp SL-series Zaurus “Qtopia” Development Start-up Guide
Ver 1.11, February 28, 2003, 33/63
Add SLOT definition to the class definition
In order to create your own slot, you would have to add a Q_OBJECT statement in the ordinary class definition. In
addition, you would also have to add a definition of your own SLOT that you are about to create, by stating the
SLOT name to either
public slots:
or
private slots:
.
class myMainWindow : public Qwidget
{
Q_OBJECT
public:
myMainWindow();
public slots:
void testSlot();
private:
Qlabel *mylabel;
};
Create the actual SLOT
You do not need any special tricks to implement your own SLOT. Code your SLOT just like you do for the
functions and methods you implement.
Connect SIGNAL and SLOT
Use
connect
method to connect the SIGNAL and the SLOT. The following is an example that executes the
created
testSlot
when mybutton is clicked.
Connect( mybutton, SIGNAL(clicked()), this, SLOT( testSlot()) );
Using “moc” (Meta Object Compiler)
The SIGNAL and SLOT framework is Qt specific, and thus you need to do the necessary task for the compilation.
As mentioned earlier, you need to use a “moc” tool to generate source file(s) so that the C++ compiler can
recognize and handle the code. (See section 2.2.3 for the “moc” tool information.)