user1036908
user1036908

Reputation: 861

Connect Signal and Slots in QT

Is it possible to connect a signal of class A to its own slot

Example as connect(objecta1, Signala1,objecta1,slota1)

Upvotes: 0

Views: 213

Answers (2)

Martin Romañuk
Martin Romañuk

Reputation: 1110

Yes, it's very simple for example a QTimer:

myClass::myClass(QObject * parent):QObject(parent) {
    timer = new QTimer();
    timer->setSingleShot(true);
    connect(timer, SIGNAL(timeout()), this, SLOT(myClassTimeout() ));
    timer->start(1000);
}

Then you have

void myClass::myClassTimeout() { 
//...
}

Upvotes: 0

Lohrun
Lohrun

Reputation: 6732

Yes, a class can react to its own signals. Be careful to not emit the signal from the triggered slots though.

Upvotes: 3

Related Questions