• 16446阅读
  • 8回复

QDialog的accepted()信号的疑惑【已解决】 [复制链接]

上一主题 下一主题
离线wywwh
 
只看楼主 倒序阅读 楼主  发表于: 2010-06-21
请问qdialog的accepted()信号是由什么事件发出的,是不是在accept()函数中发出的,如果是的话为什么连不到槽上呢?
代码如下(mydialog是widget的子窗口):

在mydialog中有如下语句,并且点击okButton时语句生效:
connect( okButton,SIGNAL(clicked()),this,SLOT(accept()) );

在mywidget中如下,但是并不会出现消息框:
connect( mydialog,SIGNAL(accepted()),this,SLOT(dosth()) );

void mywidget::dosth()
{
     QMessageBox(QMessageBox::Information,tr("Information"),tr("Success!"));
}

怎么会出现这种情况,望高手解答,谢谢!

[ 此帖被wywwh在2010-06-22 08:28重新编辑 ]
离线xtfllbl

只看该作者 1楼 发表于: 2010-06-21

void QDialog::accepted ()   [signal]
This signal is emitted when the dialog has been accepted either by the user or by calling accept() or done() with the QDialog::Accepted argument.
Note that this signal is not emitted when hiding the dialog with hide() or setVisible(false). This includes deleting the dialog while it is visible.





void QDialog::done ( int r )   [virtual slot]
Closes the dialog and sets its result code to r. If this dialog is shown with exec(), done() causes the local event loop to finish, and exec() to return r.
As with QWidget::close(), done() deletes the dialog if the Qt::WA_DeleteOnClose flag is set. If the dialog is the application's main widget, the application terminates. If the dialog is the last window closed, the QApplication::lastWindowClosed() signal is emitted.
See also accept(), reject(), QApplication::activeWindow(), and QApplication::quit().
void QDialog::accept ()   [virtual slot]
Hides the modal dialog and sets the result code to Accepted.



上海欢迎您
离线xtfllbl

只看该作者 2楼 发表于: 2010-06-21

在mydialog中有如下语句,并且点击okButton时语句生效:
connect( okButton,SIGNAL(clicked()),this,SLOT(accept()) );
在mywidget中如下,但是并不会出现消息框:
connect( mydialog,SIGNAL(accepted()),this,SLOT(dosth()) );

为何不直接 connect( okButton,SIGNAL(clicked()),this,SLOT(dosth()) );
上海欢迎您
离线wywwh
只看该作者 3楼 发表于: 2010-06-21
这么说要自己重写accept()函数了,我试一下,谢谢版主
离线wywwh
只看该作者 4楼 发表于: 2010-06-21
回 2楼(xtfllbl) 的帖子
okButton是mydialog的子部件,不是mywidget的,mydialog是在mywidget激活的一个对话框
离线wywwh
只看该作者 5楼 发表于: 2010-06-21
引用第2楼xtfllbl于2010-06-21 13:18发表的 :
为何不直接 connect( okButton,SIGNAL(clicked()),this,SLOT(dosth()) );


okButton是mydialog的子部件,不是mywidget的,mydialog是在mywidget激活的一个对话框
离线wywwh
只看该作者 6楼 发表于: 2010-06-21
Note that this signal is not emitted when hiding the dialog with hide() or setVisible(false). This includes deleting the dialog while it is visible.

这一句怎么理解?查看源码发现accept()与reject()都是先调用hide(),然后发射accepted()或rejected()信号,源码与上面解释为什么矛盾,呼唤高手回答
离线xtfllbl

只看该作者 7楼 发表于: 2010-06-21
还在纠结这个问题阿,不用他不就是了,自己写个信号,写个槽,曹接受click,然后发送自己的信号。。。
为什么非要纠结在qt给的东西上呢?
上海欢迎您
离线wywwh
只看该作者 8楼 发表于: 2010-06-22
引用第7楼xtfllbl于2010-06-21 17:07发表的 :
还在纠结这个问题阿,不用他不就是了,自己写个信号,写个槽,曹接受click,然后发送自己的信号。。。
为什么非要纠结在qt给的东西上呢?

谢谢,已解决
快速回复
限100 字节
 
上一个 下一个