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. Pass variable value from Dialog to MainWindow
Forum Updated to NodeBB v4.3 + New Features

Pass variable value from Dialog to MainWindow

Scheduled Pinned Locked Moved Solved General and Desktop
34 Posts 5 Posters 6.3k 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #21

    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 ?

    TheCipo76T 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #22

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      TheCipo76T 1 Reply Last reply
      2
      • mrjjM mrjj

        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 ?

        TheCipo76T Offline
        TheCipo76T Offline
        TheCipo76
        wrote on last edited by
        #23

        @mrjj Yes:
        in dialog qdebug print BaudRate 9600
        in mainwindow qdebug print 115200 both Before and After

        mrjjM 1 Reply Last reply
        0
        • SGaistS SGaist

          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.

          TheCipo76T Offline
          TheCipo76T Offline
          TheCipo76
          wrote on last edited by TheCipo76
          #24

          @SGaist OK, i've fixed it as you suggested

          1 Reply Last reply
          0
          • TheCipo76T TheCipo76

            @mrjj Yes:
            in dialog qdebug print BaudRate 9600
            in mainwindow qdebug print 115200 both Before and After

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #25

            @TheCipo76
            Hmm that seems almost impossible :)
            I must be missing something.
            So function seems to return expected result.
            Just to 100% sure, please try

            qDebug() << "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 ?

            TheCipo76T 1 Reply Last reply
            0
            • mrjjM mrjj

              @TheCipo76
              Hmm that seems almost impossible :)
              I must be missing something.
              So function seems to return expected result.
              Just to 100% sure, please try

              qDebug() << "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 ?

              TheCipo76T Offline
              TheCipo76T Offline
              TheCipo76
              wrote on last edited by TheCipo76
              #26

              @mrjj

              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"

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #27

                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 ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                TheCipo76T 1 Reply Last reply
                2
                • SGaistS SGaist

                  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 ?

                  TheCipo76T Offline
                  TheCipo76T Offline
                  TheCipo76
                  wrote on last edited by TheCipo76
                  #28

                  @SGaist i close the dialog as ultimate instruction of OK pushbutton

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #29

                    You're calling close, not accept.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    TheCipo76T 2 Replies Last reply
                    4
                    • SGaistS SGaist

                      You're calling close, not accept.

                      TheCipo76T Offline
                      TheCipo76T Offline
                      TheCipo76
                      wrote on last edited by
                      #30

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

                      1 Reply Last reply
                      0
                      • SGaistS SGaist

                        You're calling close, not accept.

                        TheCipo76T Offline
                        TheCipo76T Offline
                        TheCipo76
                        wrote on last edited by
                        #31

                        @SGaist OK, finally works!!! Thanks to all

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #32

                          There's no need to call close, accept will close the dialog for you.

                          Likely because you are calling getBaudRate in several places.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

                            Ah, i was fooled by
                            qDebug() << "After" << BaudRate;
                            as its inside the if for Accepted so i assumed that was in order :)
                            Good found!

                            1 Reply Last reply
                            0
                            • TheCipo76T Offline
                              TheCipo76T Offline
                              TheCipo76
                              wrote on last edited by
                              #34

                              Thanks to all!!

                              1 Reply Last reply
                              0

                              • Login

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