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. QLineEdit Find child crashes

QLineEdit Find child crashes

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 751 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.
  • U Offline
    U Offline
    Ucn_
    wrote on last edited by Ucn_
    #1

    Hello. How do I find a child of lineEdit created in designer. This is what I tried, but it crashes

    QLineEdit *buttonx =  this ->findChild<QLineEdit *>("lineEdit_8", Qt::FindDirectChildrenOnly)->setText("Some Text");
    
    QLineEdit *button = parentWidget()->findChild<QLineEdit *>("lineEdit_8", Qt::FindDirectChildrenOnly)->setText("Some Text");
    
    QLineEdit *buttonx = centralWidget()->findChild<QStackedWidget *>("stackedWidget_2")->findChild<QGroupBox *>("groupBox_4")->findChild<QLineEdit *>("lineEdit_8")->setText("Some Text");
    

    There is Vertical Layout, inside that there is stackedWidget, inside the stackedWidget there is a groupbox, then horizontal layout. the lineEdit is inside horizontal layout. How can I access this? Thanks

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #9

      The put all your QLineEdit pointer into a QVector and iterate over them.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

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

        Hi,

        Since you are using designer, all the widgets are accessible through the ui object so why do you want to use findChild ?

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

        U 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          Since you are using designer, all the widgets are accessible through the ui object so why do you want to use findChild ?

          U Offline
          U Offline
          Ucn_
          wrote on last edited by
          #3

          @SGaist I would like to send the names of lineEdits on button click, I have a function to process many qlineEdits and I wouldn't like to type each ui->lineEdit. My solution was to only send the name and based on the name apply something to that specific lineEdit.

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

            Send the names of linedits ? Can you give a bit more details about your goal ?

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

            U 2 Replies Last reply
            0
            • SGaistS SGaist

              Send the names of linedits ? Can you give a bit more details about your goal ?

              U Offline
              U Offline
              Ucn_
              wrote on last edited by
              #5
              This post is deleted!
              1 Reply Last reply
              0
              • SGaistS SGaist

                Send the names of linedits ? Can you give a bit more details about your goal ?

                U Offline
                U Offline
                Ucn_
                wrote on last edited by
                #6

                @SGaist for example:

                I have a function processLineEdits(QString lineEditname) and a private slot on_pushButton_3_clicked()

                void someClass::on_pushButton_3_clicked(){
                
                   processLineEdits(lineEdit->objectName())
                }
                
                
                void someClass::processLineEdits(QString lineEditname){
                
                QLineEdit *buttonx =  this ->findChild<QLineEdit *>(lineEditname, Qt::FindDirectChildrenOnly);
                
                buttonx ->setText("Some Text");
                
                }
                
                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  And why not simply pass the QLineEdit pointer here?

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  U 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    And why not simply pass the QLineEdit pointer here?

                    U Offline
                    U Offline
                    Ucn_
                    wrote on last edited by
                    #8

                    @Christian-Ehrlicher I have many lineEdits and many slots each slot sends one lineEdit name to the processLineEdits(). This function receives any lineEdit name checks the echoMode if is normal then sets to password and if is password then it sets to normal. It shows and hides text. With something like this I don't need to do it one lineEdit by one, I want the function to handle for all qLineEdit by name.

                    1 Reply Last reply
                    0
                    • Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      The put all your QLineEdit pointer into a QVector and iterate over them.

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

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

                        Wouldn't it better to create a custom widget containing your lined edits and buttons and give it a proper interface to do what you want to do ?

                        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
                        • Christian EhrlicherC Christian Ehrlicher

                          The put all your QLineEdit pointer into a QVector and iterate over them.

                          U Offline
                          U Offline
                          Ucn_
                          wrote on last edited by
                          #11

                          @Christian-Ehrlicher Thanks, it worked.

                          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