Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get the values entered in the Main Window from a newly open Dialog ?
Qt 6.11 is out! See what's new in the release blog

How to get the values entered in the Main Window from a newly open Dialog ?

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 6 Posters 5.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lazy93

    Hi what i want to know is how to pass the value entered from mainwindow to dialog ? I tried connect signal and slot. But that didnt work. Connect Signal and Slot only works if you already open Form A and then you open Form B, key in the data and pass it back to form A. What i want to do is to key in some data in form A and when I open Form B, i can get the data from Form A.

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #11

    @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?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Lazy93
      wrote on last edited by
      #12

      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();

      jsulmJ 1 Reply Last reply
      0
      • L Lazy93

        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();

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #13

        @Lazy93 Then fix the problem. Please take a closer look at the constructor...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #14

          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 nothing

          Dialog *dialog = new Dialog;

          so you need at least
          Dialog *dialog = new Dialog(playerNumberVariable);

          1 Reply Last reply
          2
          • L Offline
            L Offline
            Lazy93
            wrote on last edited by
            #15

            Hi mrjj , How do i insert value into playernumber then ?

            jsulmJ 1 Reply Last reply
            0
            • L Lazy93

              Hi mrjj , How do i insert value into playernumber then ?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #16

              @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
              "

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • L Offline
                L Offline
                Lazy93
                wrote on last edited by
                #17

                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 ?

                }

                jsulmJ 1 Reply Last reply
                0
                • L Lazy93

                  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 ?

                  }

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #18

                  @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?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    Lazy93
                    wrote on last edited by
                    #19

                    Hi, How do i call the value from Dialog ?

                    jsulmJ 1 Reply Last reply
                    0
                    • L Lazy93

                      Hi, How do i call the value from Dialog ?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by jsulm
                      #20

                      @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;
                      }
                      

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      2

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved