为什么类中的对话框没有执行?
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
connect(ui->addButton , SIGNAL(clicked()) , this , SLOT(addItem()));
connect(ui->editButton , SIGNAL(clicked()) , this , SLOT(editItem()));
connect(ui->deleteButton , SIGNAL(clicked()) , this , SLOT(deleteItem()));
}
void Dialog::addItem()
{
EditDialog dlg(this);
dlg.show();
if(dlg.exec() == EditDialog::Accepted)
{
ui->list->addItem(dlg.name() + "--" + dlg.number());
}
}
这是一个添加项目的类对话框。 当我运行程序并单击按钮执行对话框时,它没有执行任何操作,那么解决方案是什么?
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
connect(ui->addButton , SIGNAL(clicked()) , this , SLOT(addItem()));
connect(ui->editButton , SIGNAL(clicked()) , this , SLOT(editItem()));
connect(ui->deleteButton , SIGNAL(clicked()) , this , SLOT(deleteItem()));
}
void Dialog::addItem()
{
EditDialog dlg(this);
dlg.show();
if(dlg.exec() == EditDialog::Accepted)
{
ui->list->addItem(dlg.name() + "--" + dlg.number());
}
}
That a class Dialog to Add Items.
When I run the program and click the Button to execute the Dialog it doesn't do anything so What is the solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
则需要使用 QDialog::Accepted
如果您查看文档,
QDialog::exec
,您将看到它从QDialog::DialogCode
枚举返回一个值 - 其值为QDialog::Accepted
> 和QDialog::拒绝
。You need to use QDialog::Accepted
If you look at the docs for
QDialog::exec
, you will see that it returns a value from theQDialog::DialogCode
enum - the values for which areQDialog::Accepted
andQDialog::Rejected
.