Qt/Lesson 2

< Qt

Signals and SlotsEdit

You need to use Signals and Slots to give functionality to various components of Qt. For example, you might need the program to close the window, if the user clicks the Close Button.

#include <QApplication>
#include <QPushButton>

int main(int argc,char *argv[])
    QApplication A1(argc,argv);
    QPushButton *Close = new QPushButton("Close");
    QObject::connect(Close, SIGNAL(clicked()), &A1, SLOT(quit()));
    return A1.exec();


When the user clicks the Close Button, the Signal clicked() is generated from the Close Button and is associated with quit slot of the A1(Our Application)using the QObject::connect call. The quit() function closes the window and returns control to the Operating System.