PDA

View Full Version : C++/Qt5.10.1 - Getting returned data from QDialog



jimbo
11th April 2018, 10:25
Hello,

I've sort of got it working, but still missing something.
As you can see the results I'm getting from "if (dlg.exec() == QDialog::Accepted)" are
always from the reject choice.
Help please.

Regards


Results:-
reject "returnded - ok" - OK button
reject "returnded - rej" - cancel button
reject "returnded - rej" - Dialog 'X' button
reject "returnded - rej" - menu exit

calling Dialog:-
divideoptionsdlg dlg(passedData, parent);
QObject::connect( &dlg, SIGNAL(returnData(QString)), this, SLOT(gotReturnedData(QString)) );
if (dlg.exec() == QDialog::Accepted)
{
qDebug() << "accept " << returned; //ok button
}
else
{
qDebug() << "reject " << returned; //cancel button
}

callled Dialog:-
QDialogButtonBox *B1 = new QDialogButtonBox(this);
B1->setGeometry( this->width() / 2, this->height() - 30, (this->width() / 2) - 5, 30 );
B1->addButton(tr("OK"), QDialogButtonBox::AcceptRole);
B1->addButton(tr("Cancel"),QDialogButtonBox::RejectRole);
QObject::connect( B1, SIGNAL(accepted()), this, SLOT(onOKclickedSlot()) );
QObject::connect( B1, SIGNAL(rejected()), this, SLOT(reject()) );

void divideoptionsdlg::onOKclickedSlot()
{
QString data = "returnded - ok";
emit returnData(data);
this->close();
}

divideoptionsdlg::~divideoptionsdlg()
{
QString data = "returnded - rej";
emit returnData(data);
}

ChrisW67
11th April 2018, 12:55
In onOKclickedSlot() call accept() not close();

jimbo
11th April 2018, 13:30
In onOKclickedSlot() call accept() not close();

Many thanks

Regards