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

Dynamic container

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 1.2k 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.
  • G Offline
    G Offline
    glararan
    wrote on last edited by
    #1

    Hello,

    I'm looking for dynamic container. I used QLinkedList, QList, QVector, QMap, QHash but none of them are dynamically.

    What actually I'm looking for or what I mean?
    @int b = 5;

    Container cont;
    cont[0] = b; // syntax like QMap

    b = 10;

    qDebug() << cont[0]; // Output 10@

    Define parameter with value "a"

    Add to container

    Change parameter to value "b"

    Debugging container -> output is "b"

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Buckets
      wrote on last edited by
      #2

      looking at your example why don't you just use an array of items? Doesn't really seem like you need it to be "dynamic":http://www.cplusplus.com/doc/tutorial/dynamic/.

      If you have a Qlist<int> you can change the int at any valid node you want.

      @void foo()
      {
      QList<int> list_of_ints;
      list_of_ints.append(12);
      qDebug() << list_of_ints[0];
      lis_of_ints[0] = 30;
      qDebug() << list_of_ints[0];
      list_of_ints.replace(0, 42);
      qDebug() << list_of_ints[0];

      }@

      ba ba ba
      ba na na na

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbzhang800
        wrote on last edited by
        #3

        Hi, you need to use pointers(or references) instead values.

        Or you can take a look at the source code of a dynamic language interpreter, such as Python, to see in which way c pointers are used.

        [quote author="glararan" date="1375221456"]
        What actually I'm looking for or what I mean?
        @int *b;
        *b = 5;

        Container cont;
        cont[0] = b; // syntax like QMap

        *b = 10;

        qDebug() << *cont[0]; // Output 10@

        Define parameter with value "a"

        Add to container

        Change parameter to value "b"

        Debugging container -> output is "b"

        [/quote]

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          As 1+1=2 states, you can store pointers or references instead. Alternatively, you can store explicitly shared values in the container. There really are not much more than a nice value-based wrapper around a shared data pointer.

          Note that all Qt containers take copies of the values you put in, so you need to put a type inside your container for which the copy still represents the same underlying data: a reference, a pointer or a construct like an explicitly shared value.

          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