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. [SOLVED] QList::operator<< or QList::append()?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QList::operator<< or QList::append()?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.9k 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.
  • I Offline
    I Offline
    isaacEnrique
    wrote on last edited by
    #1

    Greetings.

    Similar to my previous post, now I'm undecided about which is more convenient to use to add items to a constant QList (more precisely, a const QList< cv::Mat >& ):

    (1) QList::operator <<

    or

    (2) QList::append()

    In both cases, considering the version that adds only one element at a time.

    Do they have the same performance? or one is better than the other?

    Thanks in advance for any help and/or suggestions.

    Isaac Pérez
    Programming is understanding.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You can also use QList::operator+= :-)

      I think they are all the same, choose the one you like best. You can, of course, ask Thiago (the maintainer of QtCore) about this, he may know a lot about performance considerations, but I doubt this is really that important. Remember the famous quote about premature optimisation ;-)

      (Z(:^

      1 Reply Last reply
      0
      • I Offline
        I Offline
        isaacEnrique
        wrote on last edited by
        #3

        Thank you.

        As in my previous post, I guess that being a constant QList, the various options will have a similar performance. However, no hurts to ask.

        Isaac Pérez
        Programming is understanding.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          In the QList header file you'll find:
          @inline QList<T> &operator+=(const T &t) {
          append(t); return *this;
          }
          inline QList<T> &operator<< (const T &t) {
          append(t); return *this;
          }@

          So using append() directly saves one indirection, but due to the inlining I'd doubt it makes a real difference on performance.

          --

          When adding multiple elements, using << has the advantage you can do:
          @myList << a << b << c << d;@

          Probably not faster than multiple append()'s, but clearer code ;-)

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          1 Reply Last reply
          0
          • I Offline
            I Offline
            isaacEnrique
            wrote on last edited by
            #5

            Thanks for the information MuldeR, now the matter is clarified.

            Isaac Pérez
            Programming is understanding.

            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