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. how to set save variables into a QList iterating it?
Forum Updated to NodeBB v4.3 + New Features

how to set save variables into a QList iterating it?

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

    Wanting to save variables through a for but those variables bring the same name and those are identified at a number, how to save those variables in a for loop? and after it change their value by reference.

    example:

    QLabel variable_1, variable_2, variable_3;
    QList<QLabel> list;
       for (int i = 1 ; i == 3; ++i) {
       list.append(variable_i);
       }
    
       for (int i = 1 ; i == 3; ++i) {
           *list->setText("VALUE ");
       }
    
    

    Maybe there are a better way to do this because it bring an error when execute the code.

    Thanks

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

      @ripley said in how to set save variables into a QList iterating it?:

      QList<QLabel>

      First this won't work - you can save a pointer to an object in a container but not the object itself.
      Second - you want a vector, not a list

      Storing them in a loop is possible but I don't think it's really needed for three elements

      for (QLabel *l : {variable_1, variable_2, variable_3})
        list.push_back(l);
      

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

      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