Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. From QLineEdit Dialog to MainWindows
Qt 6.12 LTS is out! See what's new in the release blog

From QLineEdit Dialog to MainWindows

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 4 Posters 2.8k Views
  • 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.
  • A aim0d

    Hi!
    I've been looking everywhere for 2 days now to understand this but still I dont get it.
    I've a Dialog created with a .ui file and I have QLineEdit where I enter some input and I would like to take this input from the Dialog to the MainWindow.
    How can I do it?

    I tried different code and this is the last one I tried (written in the Dialog)-> connect(this->ui->cp_PM, SIGNAL(textEdited(QString)), MainWindow, SLOT(ui->glmF->setText(QString)));

    This is a code I found online and works just fine but I need something similar from a Dialog to MainWindow -> connect(this->ui->pmFV, SIGNAL(textEdited(QString)), ui->glmF, SLOT(setText(QString)));

    I tried looked at the doc in the Signal and Slot chapter, but it's not very clear

    Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #3
    This post is deleted!
    1 Reply Last reply
    0
    • jsulmJ jsulm

      @aim0d said in From QLineEdit Dialog to MainWindows:

      How can I do it?

      Add a getter method to your dialog which returns the data you need. No need for signals/slots here.

      // In MainWindow
      Dialog dlg;
      dlg.exec();
      QString value = dlg.getResult();
      
      // In Dialog
      QString Dialog::getResult()
      {
          return ui->pmFV->text();
      }
      
      A Offline
      A Offline
      aim0d
      wrote on last edited by aim0d
      #4

      @jsulm It worked, thanks!
      Just a quick question: I'm actually have more QLineEdit value to transfer from Dialog to MW;
      I tried via getValuePar():

      dialog.cpp

      QString parametri::getValuePar()
      {
          QString pmFV =  ui->pmFV->text();    
         QString glmF = ui->glmF->text();    
           QString icpF =ui->icpF->text();    
           QString gamEP =ui->gamEP->text();    
            QString icpEP = ui->icpEP->text();
          return pmFV + glmF;
      }
      
      QString parametri::getResult()
      {
          return getValuePar();
      }
      

      MainWindow,cpp

      void MainWindow::on_parametri_clicked()
      {
          class parametri pd;
          pd.exec();
          QString value = pd.getResult();
          qDebug() << value;
      }
      

      When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog

      Christian EhrlicherC jsulmJ J.HilkJ A 4 Replies Last reply
      0
      • A aim0d

        @jsulm It worked, thanks!
        Just a quick question: I'm actually have more QLineEdit value to transfer from Dialog to MW;
        I tried via getValuePar():

        dialog.cpp

        QString parametri::getValuePar()
        {
            QString pmFV =  ui->pmFV->text();    
           QString glmF = ui->glmF->text();    
             QString icpF =ui->icpF->text();    
             QString gamEP =ui->gamEP->text();    
              QString icpEP = ui->icpEP->text();
            return pmFV + glmF;
        }
        
        QString parametri::getResult()
        {
            return getValuePar();
        }
        

        MainWindow,cpp

        void MainWindow::on_parametri_clicked()
        {
            class parametri pd;
            pd.exec();
            QString value = pd.getResult();
            qDebug() << value;
        }
        

        When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #5

        @aim0d said in From QLineEdit Dialog to MainWindows:

        When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog

        What do you expect? I mean - what should this do:

        QString parametri::getValuePar()
        {
            ui->pmFV->text();
            ui->glmF->text();
            ui->icpF->text();
            ui->gamEP->text();
        }
        

        Please learn c++ basics.

        A 1 Reply Last reply
        0
        • A aim0d

          @jsulm It worked, thanks!
          Just a quick question: I'm actually have more QLineEdit value to transfer from Dialog to MW;
          I tried via getValuePar():

          dialog.cpp

          QString parametri::getValuePar()
          {
              QString pmFV =  ui->pmFV->text();    
             QString glmF = ui->glmF->text();    
               QString icpF =ui->icpF->text();    
               QString gamEP =ui->gamEP->text();    
                QString icpEP = ui->icpEP->text();
              return pmFV + glmF;
          }
          
          QString parametri::getResult()
          {
              return getValuePar();
          }
          

          MainWindow,cpp

          void MainWindow::on_parametri_clicked()
          {
              class parametri pd;
              pd.exec();
              QString value = pd.getResult();
              qDebug() << value;
          }
          

          When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog

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

          @aim0d said in From QLineEdit Dialog to MainWindows:

          I'm actually have more QLineEdit value to transfer from Dialog to MW

          Either create a getter method for each of them or create a structure where you put all these strings and implement a getter method which returns this struct.

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

          A 1 Reply Last reply
          2
          • A aim0d

            @jsulm It worked, thanks!
            Just a quick question: I'm actually have more QLineEdit value to transfer from Dialog to MW;
            I tried via getValuePar():

            dialog.cpp

            QString parametri::getValuePar()
            {
                QString pmFV =  ui->pmFV->text();    
               QString glmF = ui->glmF->text();    
                 QString icpF =ui->icpF->text();    
                 QString gamEP =ui->gamEP->text();    
                  QString icpEP = ui->icpEP->text();
                return pmFV + glmF;
            }
            
            QString parametri::getResult()
            {
                return getValuePar();
            }
            

            MainWindow,cpp

            void MainWindow::on_parametri_clicked()
            {
                class parametri pd;
                pd.exec();
                QString value = pd.getResult();
                qDebug() << value;
            }
            

            When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #7

            @aim0d said in From QLineEdit Dialog to MainWindows:

            but crashed when I click the button to open the Dialog

            I think it crashes here QString value = pd.getResult();

            because your non void function has no return statement. You should have at least a warning about this in QtCreator.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            A 1 Reply Last reply
            3
            • Christian EhrlicherC Christian Ehrlicher

              @aim0d said in From QLineEdit Dialog to MainWindows:

              When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog

              What do you expect? I mean - what should this do:

              QString parametri::getValuePar()
              {
                  ui->pmFV->text();
                  ui->glmF->text();
                  ui->icpF->text();
                  ui->gamEP->text();
              }
              

              Please learn c++ basics.

              A Offline
              A Offline
              aim0d
              wrote on last edited by
              #8

              @Christian-Ehrlicher I was trying to get every text for my QLineEdit; I wrote it like that just becuase I thought I have to wrote it like this to have the same result as the first answer i get.

              What do you expect?

              As I already said: I just want to get the texts from QLineEdit in my Dialog to my Main Window

              1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @aim0d said in From QLineEdit Dialog to MainWindows:

                but crashed when I click the button to open the Dialog

                I think it crashes here QString value = pd.getResult();

                because your non void function has no return statement. You should have at least a warning about this in QtCreator.

                A Offline
                A Offline
                aim0d
                wrote on last edited by aim0d
                #9

                @J-Hilk

                You should have at least a warning about this in QtCreator.

                I dont, because my MainWindow start and when I try to open the Dialog the terminal just says it crashed. If I had a warning first I would see it and second my application woudnt start at all

                1 Reply Last reply
                0
                • jsulmJ jsulm

                  @aim0d said in From QLineEdit Dialog to MainWindows:

                  I'm actually have more QLineEdit value to transfer from Dialog to MW

                  Either create a getter method for each of them or create a structure where you put all these strings and implement a getter method which returns this struct.

                  A Offline
                  A Offline
                  aim0d
                  wrote on last edited by
                  #10

                  @jsulm

                  create a structure where you put all these strings and implement a getter method which returns this struct.

                  I actually dont know how to do that. It the right way I mean. It's already been 2days i'm trying to have this :(

                  1 Reply Last reply
                  0
                  • A aim0d

                    @jsulm It worked, thanks!
                    Just a quick question: I'm actually have more QLineEdit value to transfer from Dialog to MW;
                    I tried via getValuePar():

                    dialog.cpp

                    QString parametri::getValuePar()
                    {
                        QString pmFV =  ui->pmFV->text();    
                       QString glmF = ui->glmF->text();    
                         QString icpF =ui->icpF->text();    
                         QString gamEP =ui->gamEP->text();    
                          QString icpEP = ui->icpEP->text();
                        return pmFV + glmF;
                    }
                    
                    QString parametri::getResult()
                    {
                        return getValuePar();
                    }
                    

                    MainWindow,cpp

                    void MainWindow::on_parametri_clicked()
                    {
                        class parametri pd;
                        pd.exec();
                        QString value = pd.getResult();
                        qDebug() << value;
                    }
                    

                    When I run the project It opens the MainWindow but crashed when I click the button to open the Dialog

                    A Offline
                    A Offline
                    aim0d
                    wrote on last edited by
                    #11

                    @aim0d I change it
                    but the result is the two values united like these are the values:
                    QString pmFV = ui->pmFV->text(123);
                    QString glmF = ui->glmF->text(78);

                    and this is the output in qDebug() -> 12378

                    Christian EhrlicherC 1 Reply Last reply
                    0
                    • A aim0d

                      @aim0d I change it
                      but the result is the two values united like these are the values:
                      QString pmFV = ui->pmFV->text(123);
                      QString glmF = ui->glmF->text(78);

                      and this is the output in qDebug() -> 12378

                      Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @aim0d said in From QLineEdit Dialog to MainWindows:

                      QString pmFV = ui->pmFV->text(123);
                      QString glmF = ui->glmF->text(78);

                      This does not even compile...

                      How about some c++ basics before starting with Qt

                      I actually dont know how to do that. It the right way I mean.

                      See e.g QString::append()

                      A 1 Reply Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        @aim0d said in From QLineEdit Dialog to MainWindows:

                        QString pmFV = ui->pmFV->text(123);
                        QString glmF = ui->glmF->text(78);

                        This does not even compile...

                        How about some c++ basics before starting with Qt

                        I actually dont know how to do that. It the right way I mean.

                        See e.g QString::append()

                        A Offline
                        A Offline
                        aim0d
                        wrote on last edited by aim0d
                        #13

                        @Christian-Ehrlicher It gives me what I need in the wrong way
                        I dont have actual time to learn c++ in a right way; this is a work project and give me this stuff to do knowing I know very little of c++

                        And I repeat, this give me the output I wrote in my last comment, but not in the format I need

                        This does not even compile...

                        it was and example to let you understand the output for god sake, it's not my actual code if you have to answer pls at least try to understan what I'm writing

                        Christian EhrlicherC jsulmJ 2 Replies Last reply
                        0
                        • A aim0d

                          @Christian-Ehrlicher It gives me what I need in the wrong way
                          I dont have actual time to learn c++ in a right way; this is a work project and give me this stuff to do knowing I know very little of c++

                          And I repeat, this give me the output I wrote in my last comment, but not in the format I need

                          This does not even compile...

                          it was and example to let you understand the output for god sake, it's not my actual code if you have to answer pls at least try to understan what I'm writing

                          Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by Christian Ehrlicher
                          #14

                          @aim0d said in From QLineEdit Dialog to MainWindows:

                          I dont have actual time to learn c++ in a right way;

                          Then you're wrong here.

                          And I repeat, this give me the output I wrote in my last comment, but not in the format I need

                          It does not compile since QLineEdit has not function text() which takes an integer.

                          I'm out here.

                          1 Reply Last reply
                          0
                          • A aim0d

                            @Christian-Ehrlicher It gives me what I need in the wrong way
                            I dont have actual time to learn c++ in a right way; this is a work project and give me this stuff to do knowing I know very little of c++

                            And I repeat, this give me the output I wrote in my last comment, but not in the format I need

                            This does not even compile...

                            it was and example to let you understand the output for god sake, it's not my actual code if you have to answer pls at least try to understan what I'm writing

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

                            @aim0d said in From QLineEdit Dialog to MainWindows:

                            I dont have actual time to learn c++ in a right way

                            Do you think it is better/more efficient to spend a lot of time in a forum to get help for issues you would not have if you would learn the basics of the programming language you're using? You should really reconsider your approach...

                            struct is one of the most basic things in C++:

                            struct Data
                            {
                                QString data1;
                                QString data2;
                                ...
                            }
                            
                            Data parametri::getValuePar()
                            {
                                Data result;
                                result.data1 = ui->pmFV->text();
                                result.data2 = ui->glmF->text();
                                ...
                                return result;
                            }
                            

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

                            A 1 Reply Last reply
                            2
                            • jsulmJ jsulm

                              @aim0d said in From QLineEdit Dialog to MainWindows:

                              I dont have actual time to learn c++ in a right way

                              Do you think it is better/more efficient to spend a lot of time in a forum to get help for issues you would not have if you would learn the basics of the programming language you're using? You should really reconsider your approach...

                              struct is one of the most basic things in C++:

                              struct Data
                              {
                                  QString data1;
                                  QString data2;
                                  ...
                              }
                              
                              Data parametri::getValuePar()
                              {
                                  Data result;
                                  result.data1 = ui->pmFV->text();
                                  result.data2 = ui->glmF->text();
                                  ...
                                  return result;
                              }
                              
                              A Offline
                              A Offline
                              aim0d
                              wrote on last edited by
                              #16

                              @jsulm

                              Do you think it is better/more efficient to spend a lot of time in a forum to get help for issues you would not have if you would learn the basics of the programming language you're using? You should really reconsider your approach...

                              I know, but as I said it's a project my boss gives me with a deadline in a week and they know I have little experience in C++; so i'm stuck here trying to build something with what I know and I found online

                              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
                              • Unsolved