Unsolved What are the differences between accept and setResult
-
Hello everyone,
Could somebody give me some advice?I create a sub dialog. I want to set the result to Accepted when I click some button. So I use code "setResult(Accepted)" in the slot function. But it doesn't work. The result is still Rejected. But if I use code "accept()" in the slot function, it works.
So I wonder what are the differences between accept() and setResult(Accepted)?
Thanks in advance.
-
accept() sets the result code to Accepted and closes the dialog, setResult() only sets the result code. If your result code is not what you expect you maybe overwrite it somewhere in between.
-
@Christian-Ehrlicher
Thank you very much.
I see. I add close() after accept() and setResult(Accepted).
But the result code is not what I set by using setResult(Accepted). Do you mean I should overwrite setResult() or some other functions?
Thank you again. -
@Qingshui-Kong said in What are the differences between accept and setResult:
I add close() after accept() and setResult(Accepted).
Please show us some code - there is no need to call close() after accept(), only needed when you want to close the window when you only call setResult().
Do you show a modal dialog? If so how to you exit the dialog when calling setResult()? -
@Christian-Ehrlicher
Yes, it should be a modal dialog.
Here are some codes.
At the begining, I use setResult.
void VXFaultDialog::onBtnCloseClicked()
{
setResult(Accepted);
close();
}
But it doesn't work. So I choose accept();
void VXFaultDialog::onBtnCloseClicked()
{
accept();
close();
}
Then it works. -
Now I understand what you want. This is due to the fact that QDialog::closeEvent() sets the result code depending on the visibility of the dialog since this event can also be triggered from the outside. I would recommend to use accept()/reject()/done() as this is the recommended way stated in the documentation.
-
@Christian-Ehrlicher
OK. Thank you very much. -
@Christian-Ehrlicher
I use accept() or reject(). But the dialog doesn't close automatically. I have to use close() to close it.