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. QList with unknown number of items
Qt 6.11 is out! See what's new in the release blog

QList with unknown number of items

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 412 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.
  • jipe3001J Offline
    jipe3001J Offline
    jipe3001
    wrote on last edited by aha_1980
    #1

    I am using a Qlist declared as follows:

    QList <QWidget *> List_a;

    Of course I can add items with List_a.append(W1);

    assuming W1 is a Widget declared before

    but my concern is that I do not know how many Widget I will have to add
    to List_a (depending of a file content read before).

    How could I create these widgets in a loop and then add to the Qlist ?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You mean new them ?
      for (int c=0; c < 100; c++) {
      List_a.append( new QPushButton );
      }
      would add 100 push buttons.

      However, what will you you use the widgets for ?
      If you assign them a parent, and delete parent, then it will
      delete the Widgets too and list would contain invalid pointers.

      So what are you planning to do with these widgets ?

      1 Reply Last reply
      5
      • jipe3001J Offline
        jipe3001J Offline
        jipe3001
        wrote on last edited by
        #3

        Thks mrjj it fixed my problem

        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