Solved Pass variable value from Dialog to MainWindow
-
Hi
Its a bit odd as you seem to set BaudRate in
void ImpostazioniSP::on_pushButton_OK_clicked()
so in
QString ImpostazioniSP::getBaudRate() {
qDebug() << "BaudRate:" << BaudRate;
return BaudRate;
}does it show the value you set with comboBox_BaudRate ?
-
Why are you using that switch ? You already have the baud rate as a string in the combo box.
As already suggest, returning the combo box selected text is shorter and less error prone.
-
@mrjj Yes:
in dialog qdebug print BaudRate 9600
in mainwindow qdebug print 115200 both Before and After -
@SGaist OK, i've fixed it as you suggested
-
@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!!