• 11850阅读
  • 2回复

[讨论]Qt 中exec()的返回值是多少啊 [复制链接]

上一主题 下一主题
离线青原落枫
 

只看楼主 倒序阅读 楼主  发表于: 2012-10-10
当我选择ok而使对话框弹出时,其返回值是不是0,而选择cancel而使对话框弹出时,其返回值是不是1?
enum StdButton{OK, CANCEL};

if (QDialog::Accepted == getInst()->exec()){
  return OK;
}
else{
  return CANCEL;
}
离线ppdayz

只看该作者 1楼 发表于: 2012-10-10
int QDialog::exec () [slot]

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.

See also open(), show(), result(), and setWindowModality().

enum QDialog::DialogCode
The value returned by a modal dialog.
Constant Value

QDialog::Accepted 1

QDialog::Rejected 0

文档是这么说的

离线淳于半邪

只看该作者 2楼 发表于: 2012-10-10
看你自己都设置好了枚举enum StdButton{OK, CANCEL}; 这里的OK最好赋值为0
返回值的嘛
accepted 返回 OK 为0
rejected 返回CANCEL 为1
快速回复
限100 字节
 
上一个 下一个