Qt Signal and Slots
← Qt Widgets | ● | QPainter Example →
The interaction of user interface elements is done by so called signals and slots. They implement a (thread-safe) message passing concept to transmit information from a method of one widget to another.
The message sender is called signal.
The message receiver is called slot.
If a signal is triggered, all the slots that are registered as receiver of the signal will be invoked.
The signal/slot concept is an extension of the C++ standard. Therefore, the Qt source code needs to be pre-compiled with the so called MOC (the Qt Meta Object Compiler), which consequently produces C++ code to be compiled with a standard C++ compiler.
Example:
connect(quitAction, SIGNAL(triggered()), this, SLOT(close())); // moc keyword
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(quitAction);
void close()
{
QApplication::quit();
}
For further reading about signals and slots and the MOC see Qt-Development.
← Qt Widgets | ● | QPainter Example →