Qt emit signals
-
I can't understand why methods in signals don't need to be defined.
there is an example that you can find in Qt/examples/opengl/hellogl/glwidget.h,glwidget.cpp
@signals:
void xRotationChanged(int angle);
void yRotationChanged(int angle);
void zRotationChanged(int angle);
@ -
Thats beacuse signals only emit themself and their arguments, dont need code to work. You defina what they should do on connections.
"Check this article":http://qt-project.org/doc/qt-4.7/signalsandslots.html#id-bf5ed240-73e9-4fa9-8792-9bc16480c692 -
A Signal is a method that is emitted rather than executed when called. So we only declare prototypes of signals that might be emitted.
A Slot is a member function that can be invoked as a result of signal emission. We have to tell the compiler which method has to be treated as slots by putting them in one of the following sections:
public slots, protected slots or private slots.So as per the definition we only declare prototypes of signals that might be emitted. So in the HelloGL example we declare the prototypes
@signals:
void xRotationChanged(int angle);
void yRotationChanged(int angle);
void zRotationChanged(int angle);@and in the implementation file whenever we set the rotation we emit one of these signals and the associated Slot function is called. eg.
@void GLWidget::setXRotation(int angle)
{
//do something then
emit xRotationChanged(angle);
updateGL();
}@The signals and slots for the above example are connected in window.cpp file :
@connect(glWidget, SIGNAL(xRotationChanged(int)), xSlider, SLOT(setValue(int)));@
For more details you can read "Signals and Slots ":http://books.google.ae/books?id=nyxoEiGHKtoC&printsec=frontcover&source=gbs_ge_summary_r&cad=0#v=onepage&q&f=false topic in this ebook.
You can also refer to "Signals and Slots documentation":http://qt-project.org/doc/qt-5.0/signalsandslots.html.
-
Technically they actually are defined: Moc adds code to all classes containing the Q_OBJECT macro, incl. some that implements the signals.