PDA

View Full Version : QDialog.exec() exiting without calling QDialog::accept()



doggrant
2nd February 2011, 10:22
Hi,

In my code I have a dialog box which has an OK button. I show it by calling diag.exec(). The slot on the OK button has the following code:



void SLOTOkBtn()
{
QList<QTreeWidgetItem *> selectedItems = ui.m_PackageList->selectedItems();

if ( selectedItems.isEmpty() )
{
return;
}
else
{
// Provides you with the first selection
m_Package = selectedItems.first()->text( 0 ).toAscii().data();
QDialog::accept();
}
}


Now if I hit OK and no items are selected, it gets to return;, which is what i would expect - however, rather than staying in exec(), it is closing the dialog box, and the test on the return code from diag.exec() give QDialog::Accepted, even though QDialog::Accept() has not been called.

Any ideas what i am doing wrong?

David

nish
2nd February 2011, 11:23
put some debug statements in both if and else block. See what isEmpty() returns.

doggrant
2nd February 2011, 11:28
I've put debuging in and also stepped through the code. That's how I know it's hitting the:

return;

and not:

QDialog::accept();

I just can't work out why the dialog box goes when QDialog::accept() has not been called.

nish
2nd February 2011, 11:35
provide a minimal compilable program reproducing the problem. there is no way to help without that.