[英]QDialog::accepted() slot not working
我正在嘗試為QDialog
實現信號插槽系統。 在Google搜索之后,我在Stack Overflow上遇到了這個問題 。 這個答案看起來很有希望,所以我嘗試使用它。 我沒有收到任何錯誤,但是該插槽無法正常工作。 下面是我的代碼:
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();
}
這是我的對話框:
當我按下“ New activity
對話框上的New activity
創建”按鈕時,什么也沒有發生。 我哪里錯了?
我想您將schedule.cpp中的代碼重新排序為:
void Schedule::on_actionNew_Activity_triggered() {
newActivity *newActivityWnd = new newActivity(this, Qt::WindowTitleHint | Qt::WindowSystemMenuHint);
QObject::connect(newActivityWnd, SIGNAL(accepted()), this, SLOT(on_activityCreated()));
newActivityWnd->exec();
}
這樣可以解決您的問題嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.