QDialog类exec()与show()的区别

继承至QWidget的类都能使用show()将自身显示出来,QDialog也不例外。然而QDialog除了能使用继承至QWidget的show()方法显示自身之外,它还有另一个方法exec()同样也能将自身显示出来。那么这两个方法之间有什么区别呢?请看下面的表格对比:

原型 返回值 说明
void QWidget::show() Shows the widget and its child widgets.
int QDialog::exec()

Shows the dialog as a modal dialog, blocking until the user closes it. The function returns a DialogCode result. If the dialog is application modal, users cannot interact with any other window in the same application until they close the dialog. If the dialog is window modal, only interaction with the parent window is blocked while the dialog is open. By default, the dialog is application modal.

从表格对比中可以看出这两者的区别。首先这两个方法返回值不同。exec()有返回值,show()没有返回值。其次这两个方法的作用也不同。调用show()的作用仅仅是将widget及其上的内容都显示出来。而调用exec()后,调用线程将会被阻塞,直到Dialog关闭。

posted @ 2014-11-19 16:53  鞋匠  阅读(3511)  评论(0编辑  收藏  举报