Solved How to get the values entered in the Main Window from a newly open Dialog ?
-
@Lazy93 said in How to get the values entered in the Main Window from a newly open Dialog ?:
what i want to know is how to pass the value entered from mainwindow to dialog ?
I already explained how (no need for signals/slots). And I pointed out (in my last post) that you're doing something wrong. Did you fix the bug?
-
class MyDialog: public QDialog
{
public:
MyDialog(int playerNumber, QWidget *parent = nullptr);
}if i use this method, i cannot open my dialog with
Dialog *dialog = new Dialog;
dialog->exec();as it says no matching function for call to 'Dialog::Dialog();
-
@Lazy93 Then fix the problem. Please take a closer look at the constructor...
-
Hi
Just in case @jsulm's good hint do not ring any bells..MyDialog(int playerNumber, QWidget *parent = nullptr);
Asks for INT and optional parent
but you give it nothingDialog *dialog = new Dialog;
so you need at least
Dialog *dialog = new Dialog(playerNumberVariable); -
Hi mrjj , How do i insert value into playernumber then ?
-
@Lazy93 The user has to enter it, right? Then use this value.
Here your own description:
"
1.Start,
2.Mainwindow appear,
3.Key in the number of player, // lets say i put an X
4.Click OK/Proceed,
5.A new dialog/form will be executed, // lets say its called Dialog1
6.The number of player that has been input in the mainwindow is carried to that new form // I want to carry the value of X from the mainwindow to Dialog1
" -
Yes, but how to use the playernumber in
MyDialog(int playerNumber, QWidget *parent = nullptr); ?
i think.....
void Dialog::on_lineEdit_textEdited(const QString &arg1){
playernumber = arg1.toInt ();? / / <<<< cannot be done right ?
}
-
@Lazy93 said in How to get the values entered in the Main Window from a newly open Dialog ?:
playernumber = arg1.toInt ();? / / <<<< cannot be done right ?
it can be done, why not?
-
Hi, How do i call the value from Dialog ?
-
@Lazy93 Simply add a public getter method to your dialog:
void Dialog::on_lineEdit_textEdited(const QString &arg1){ _playernumber = arg1.toInt ();? / / <<<< cannot be done right ? } int Dialog::playerNumber() { return _playerNumber; }