class MyMainWindow:public QMainWindow {
public:
MyWindow* myWindow() { return myWindow ;}
private:
MyWindow* myWindow;
};
class MyWindow:public Qobject {
private slot:
void mySlot();
};
class MyWindow2: class QWidget {
public slot:
void refreshClick();
signals:
signal1();
};
MyWindow2::MyWindow2(QMainWindow* parent) {
QPushButton* refresh;
QObject::connect(refresh,SIGNAL(clicked()), this, SLOT(refreshClicked()));
if(parent) {
QObject::connect(this,SIGNAL(signal1),parent->myWindow(),SLOT(mySlot));
}
}
void MyWindow2::refreshClicked(){
emit signal1();
}
I want to know if it is legal to emit signal1 from slot refreshClicked and also are there any cons of emitting a signal from within a slot
Yes, it is perfectly ok. But if your only goal is to "forward" a signal, you can also connect your "incoming" signal directly to the signal you are emmitting. eg.:
connect(advisor , SIGNAL(hasAdvice()),
this , SIGNAL(executeAdvice())
)
But keep in mind that this does not always benefit the extendablity of your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With