Solved Pass variable value from Dialog to MainWindow
-
@TheCipo76
Hmm that seems almost impossible :)
I must be missing something.
So function seems to return expected result.
Just to 100% sure, please tryqDebug() << "Before" << BaudRate; ImpostazioniSP SetImp (this, BaudRate, DataBits, Parity); SetImp.setModal(true); if ( SetImp.exec() == QDialog::Accepted ) { qDebug() << "from func" << SetImp.getBaudRate(); }
and tell what "from func" says ?
-
Before "115200" (mainwindow)
BaudRate: "9600" (dialog)"from func" was not showed
i've modify you code:
qDebug() << "Before" << BaudRate; ImpostazioniSP SetImp (this, BaudRate, DataBits, Parity); SetImp.setModal(true); if ( SetImp.exec() == QDialog::Accepted ) { BaudRate=SetImp.getBaudRate(); } qDebug() << "from func" << SetImp.getBaudRate();
and this is result:
Before "115200"
BaudRate: "9600"
BaudRate: "9600"
from func "9600" -
What is stranger is that @mrjj's code is mostly the same as mine :-D
Which means that you didn't accept the dialog properly. Are you clicking on some OK button the closes it ? Or are you just clicking the X button ?
-
@SGaist i close the dialog as ultimate instruction of OK pushbutton
-
You're calling close, not accept.
-
@SGaist i have called accept before close
this is qdebug message:
Before "115200"
BaudRate: "9600"
BaudRate: "9600"
BaudRate: "9600"
from func "9600"why show BaudRate: "9600" 3 times???
-
@SGaist OK, finally works!!! Thanks to all
-
There's no need to call close, accept will close the dialog for you.
Likely because you are calling
getBaudRate
in several places. -
Ah, i was fooled by
qDebug() << "After" << BaudRate;
as its inside the if for Accepted so i assumed that was in order :)
Good found! -
Thanks to all!!