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. Values of dynamically created QLineEdit
QtWS25 Last Chance

Values of dynamically created QLineEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlayoutqlineedit
4 Posts 4 Posters 2.0k 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.
  • T Offline
    T Offline
    Tirolel
    wrote on 12 Aug 2016, 08:54 last edited by Tirolel 8 Dec 2016, 08:55
    #1

    Hi everyone.

    I want to get text values from QLineEdit which it have been added dynamically.

    I have a loop for adding these widgets to tempLayout.

    tempLayout->addWidget(new QLabel(j.key()));
    tempLayout->addWidget(new QLineEdit(j.value()));  
    

    So how I can access the values that I want from the QLineEdit? I have about 4-5 labels and 6-7 of Qlineedits.

    I have tried this but it crashes when I access it.

    int children = tempLayout->count();
    if(children > 0)
    {
        qDebug() << "Children count = "<< children;
        QString str = tr("");
        for(int i = 0; i < children; i++)
        {
            QLayoutItem* pLine = tempLayout->itemAt(i);
            pLineEdit = (QLineEdit*)pLine->widget();
           qDebug() << "Children of templayout" << pLineEdit->text();
        }
        qDebug() << "Values " << tempLayout->count();
    }
    else
    {
        qDebug() << "No children found";
    }
    
    K 1 Reply Last reply 14 Aug 2016, 01:06
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 12 Aug 2016, 08:59 last edited by
      #2

      Have you tried with

      QList<QLineEdit*> widgets = tempLayoutParent->findChildren<QLineEdit*>();
      http://doc.qt.io/qt-5/qobject.html#findChildren

      1 Reply Last reply
      3
      • V Offline
        V Offline
        VRonin
        wrote on 12 Aug 2016, 11:10 last edited by
        #3

        another way is set the objectName() of each QLineEdit and retrieve them by name

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2
        • T Tirolel
          12 Aug 2016, 08:54

          Hi everyone.

          I want to get text values from QLineEdit which it have been added dynamically.

          I have a loop for adding these widgets to tempLayout.

          tempLayout->addWidget(new QLabel(j.key()));
          tempLayout->addWidget(new QLineEdit(j.value()));  
          

          So how I can access the values that I want from the QLineEdit? I have about 4-5 labels and 6-7 of Qlineedits.

          I have tried this but it crashes when I access it.

          int children = tempLayout->count();
          if(children > 0)
          {
              qDebug() << "Children count = "<< children;
              QString str = tr("");
              for(int i = 0; i < children; i++)
              {
                  QLayoutItem* pLine = tempLayout->itemAt(i);
                  pLineEdit = (QLineEdit*)pLine->widget();
                 qDebug() << "Children of templayout" << pLineEdit->text();
              }
              qDebug() << "Values " << tempLayout->count();
          }
          else
          {
              qDebug() << "No children found";
          }
          
          K Offline
          K Offline
          kenchan
          wrote on 14 Aug 2016, 01:06 last edited by kenchan
          #4

          @Tirolel
          If you want t do it that way you shouldn't you cast the widget to find out what type it is before you actually use it?

          if(qobject_cast<QLineEdit*>(pLine->widget()) != 0)
          ...

          Test for which type it is then use the correct type cast to use the actual member functions...

          1 Reply Last reply
          0

          2/4

          12 Aug 2016, 08:59

          • Login

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