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
Forum Updated to NodeBB v4.3 + New Features

Values of dynamically created QLineEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
qlayoutqlineedit
4 Posts 4 Posters 2.0k 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.
  • TirolelT Offline
    TirolelT Offline
    Tirolel
    wrote on last edited by Tirolel
    #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
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on 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
        • TirolelT Tirolel

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

          • Login

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