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. Getting text values from dynamically created Qline edits in Qt c++
Forum Updated to NodeBB v4.3 + New Features

Getting text values from dynamically created Qline edits in Qt c++

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 1.1k 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.
  • L Offline
    L Offline
    Lasith
    wrote on last edited by
    #1

    I have created a set of Qline edits successfully and assigned each line edit an Object name but unfortunately when I try to read and get them into a QStringList I get an error stating

    "Textbox was not declared in this scope"

    my code is as follows!

    for(int i=0;i<5;i++){
    f1 = new QFrame();
    f2 = new QFrame();
    f3 = new QFrame();

    a= new QLabel(f1);
    b=new QLineEdit(f2);
    c=new QLineEdit(f3);

    QString oName= QString::number(i);
    b->setObjectName("Textbox"+oName);
    
    ui->verticalLayout->addWidget(f1);
    ui->verticalLayout_2->addWidget(f2);
    ui->verticalLayout_3->addWidget(f3);
    
    a->setText(newList[i]);
    

    }

    and from the button click event I won't to get each text in the dynamically created QLine edits!

    void NewOrders::on_pushButton_2_clicked()
    {

    for(int i=0;i<getList.size();i++){
    QString oName= QString::number(i);
    getList<<(ui->("Textbox"+oName)->text());
    }
    }

    Here getlist and newlist are QStirngLists are already defined as public! How can I correct this?

    sierdzioS 1 Reply Last reply
    0
    • L Lasith

      I have created a set of Qline edits successfully and assigned each line edit an Object name but unfortunately when I try to read and get them into a QStringList I get an error stating

      "Textbox was not declared in this scope"

      my code is as follows!

      for(int i=0;i<5;i++){
      f1 = new QFrame();
      f2 = new QFrame();
      f3 = new QFrame();

      a= new QLabel(f1);
      b=new QLineEdit(f2);
      c=new QLineEdit(f3);

      QString oName= QString::number(i);
      b->setObjectName("Textbox"+oName);
      
      ui->verticalLayout->addWidget(f1);
      ui->verticalLayout_2->addWidget(f2);
      ui->verticalLayout_3->addWidget(f3);
      
      a->setText(newList[i]);
      

      }

      and from the button click event I won't to get each text in the dynamically created QLine edits!

      void NewOrders::on_pushButton_2_clicked()
      {

      for(int i=0;i<getList.size();i++){
      QString oName= QString::number(i);
      getList<<(ui->("Textbox"+oName)->text());
      }
      }

      Here getlist and newlist are QStirngLists are already defined as public! How can I correct this?

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @Lasith said in Getting text values from dynamically created Qline edits in Qt c++:

      getList<<(ui->("Textbox"+oName)->text());

      That part is wrong. The objectName property is a property of a C++ object. It is not name of the C++ variable, and not part of ui.

      In order to get a list of QObjects with certain objectName, you should use findChild<>() method, or findChildren<>().

      Side note: in each step of your first for loop, you create 3 new QLineEdits, but you only change the objectName of one of them (b). The rest remains unnamed.

      (Z(:^

      1 Reply Last reply
      4

      • Login

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