I am trying to implement a signal-slot system for a QDialog
. After a Google search, I've got this question on Stack Overflow. That answer looks promising, so I tried to use it. I get no error, but the slot doesn't work. Below is my code:
newactivity.cpp
// in the QDialog constructor
QObject::connect(this->ui.createBtn, SIGNAL(clicked()), this, SLOT(accept()));
QObject::connect(this->ui.cancelBtn, SIGNAL(clicked()), this, SLOT(reject()));
void newActivity::accept() {
QDialog::accept(); // to close the dialog and return 1
}
void newActivity::reject() {
QDialog::reject(); // to close the dialog and return 0
}
schedule.cpp
void Schedule::on_actionNew_Activity_triggered() {
newActivity *newActivityWnd = new newActivity(this, Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
newActivityWnd->exec();
QObject::connect(newActivityWnd, SIGNAL(accepted()), this, SLOT(on_activityCreated()));
}
void Schedule::on_activityCreated() {
this->ui.timeLine->hide();
}
Here is my dialog:
Nothing happens when I press the Create button on New activity
dialog. Where am I wrong?