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. Get Value from a LineEdit in the MainWindow to be use in a dialog
Forum Updated to NodeBB v4.3 + New Features

Get Value from a LineEdit in the MainWindow to be use in a dialog

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 1.8k Views 1 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.
  • I Offline
    I Offline
    iyustlop
    wrote on last edited by iyustlop
    #1

    Hi all:

    My problem is that I want to read the value of a LineEdit in the Main Windows and then use the value in a dialog.

    This should be the first step, in case that Line has a wrong Value or is Empty an error is thrown.

    Could I getthis value during the Slot and then pass to the dialog ?

    public:
    explicit AddVisit(QWidget *parent = 0, Qstring number);
    ~AddVisit();

    Please, could someone tell me how to pass the variable after click?

    void MainWindow::on_createDatePushButton_clicked()
    {
    QString number = ui->lineEditNumber->text();
    AddVisit myAddVisit;
    myAddVisit.setModal(true);
    myAddVisit.exec();
    }

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

      Hi,

      It depends on how you are going to use that dialog.

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

      I 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        It depends on how you are going to use that dialog.

        I Offline
        I Offline
        iyustlop
        wrote on last edited by
        #3

        @SGaist The idea is have the QString Number as key in a table. Two different tables but with the same key.

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

          How are you using that dialog ?

          Are you showing it permanently ? On demand ? Are you re-creating it each time ? Can that value be changed while the dialog is shown ?

          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
          1
          • I iyustlop

            @SGaist The idea is have the QString Number as key in a table. Two different tables but with the same key.

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

            @iyustlop Why not just pass it as parameter to the dialog constructor?

            void MainWindow::on_createDatePushButton_clicked()
            {
            QString number = ui->lineEditNumber->text();
            AddVisit myAddVisit(number);
            // myAddVisit.setModal(true); <-- This is not needed as exec() already shows the dialog as modal dialog
            myAddVisit.exec();
            }
            

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

            I 1 Reply Last reply
            2
            • jsulmJ jsulm

              @iyustlop Why not just pass it as parameter to the dialog constructor?

              void MainWindow::on_createDatePushButton_clicked()
              {
              QString number = ui->lineEditNumber->text();
              AddVisit myAddVisit(number);
              // myAddVisit.setModal(true); <-- This is not needed as exec() already shows the dialog as modal dialog
              myAddVisit.exec();
              }
              
              I Offline
              I Offline
              iyustlop
              wrote on last edited by iyustlop
              #6

              @jsulm thank you for the idea. The problem is how i have to modify the construtor to include this parameter

              AddVisit::AddVisit(QWidget *parent, QString number) :
              QDialog(parent),
              ui(new Ui::AddVisit)
              {
              ui->setupUi(this);
              }

              This way, I have an error due to this constructor is not known.

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

                Did you also modify the declaration ?

                By the way, the common implementation is to have parent as last parameter.

                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
                • I Offline
                  I Offline
                  iyustlop
                  wrote on last edited by
                  #8

                  The result that works:

                  AddVisit::AddVisit(QString number, QWidget *parent, QString number) :
                  QDialog(parent),
                  ui(new Ui::AddVisit)
                  {
                  ui->setupUi(this);
                  }

                  With this costructor everything works.

                  Thank you very much indeed for the help.

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

                    Don't you have one number parameter too many ?

                    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
                    2

                    • Login

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