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. QLinkedList size at declaration?
Qt 6.11 is out! See what's new in the release blog

QLinkedList size at declaration?

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

    This might be a stupid question, but please don't shoot me down! I'm new to both C++ and Qt.

    Can size be specified at declaration in case of LinkedLists?

    @QLinkedList<int> list(10);@

    This throws me the following error:
    105: error: no matching function for call to 'QLinkedList<int>::QLinkedList(int)'

    But I've taken this line straight from the C++ GUI programming with Qt, SE.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      guziemic
      wrote on last edited by
      #2

      QLinkedList does not support predefinition of size. It growth when new element is linked to it. As I saw in "documentation":http://qt-project.org/doc/qt-4.8/QLinkedList.html there is no possibility to pre allocate size.
      But, if you need to reserve space for your list Qt offers "QList":http://qt-project.org/doc/qt-4.8/qlist.html and there is possibility to reserve space for elements "reserve":http://qt-project.org/doc/qt-4.8/qlist.html#reserve

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kchandr7
        wrote on last edited by
        #3

        Thanks, that makes sense. I guess the book is wrong then.

        1 Reply Last reply
        0
        • U Offline
          U Offline
          utcenter
          wrote on last edited by
          #4

          It makes absolutely no sense for a linked list to pre-allocate elements because elements are not stored sequentially, not only is there nothing to gain from pre-allocation but it will mess up the implementation logic of the linked list.

          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