Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    QVector append but empty

    General and Desktop
    4
    4
    2875
    Loading More Posts
    • 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.
    • H
      huckfinn last edited by

      Hello,

      a have written a return method, which should return a QVector object. This is just for testing purpose.
      Anyway, the QPoint object contains correct values.
      But when I make a appen the entries are erroneous.. My QVector has enough space, according to the l_length parameter.. But those are empty..

      @
      QVector< QPoint > MyClass::GetPointList( int l_length )
      {
      QVector< QPoint > l_return;

      for( int i = 0; i < l_length; i++ )
      {
      

      QPoint t(i, i+10);
      l_return.append(t);
      }
      return l_return;
      }
      @

      Do I make anything wrong in that piece of code?

      Thank you in advise

      Huck

      1 Reply Last reply Reply Quote 0
      • A
        andre last edited by

        No, looks fine to me, even though it could be made more efficient by initializing your vector with the correct length (saves some copies when the vector is growing).

        1 Reply Last reply Reply Quote 0
        • O
          octal last edited by

          With your current code, there is no reason it shouldn't work.

          Can you give us some more code ? Where does it not work ?

          1 Reply Last reply Reply Quote 0
          • S
            Scylla last edited by

            What does return @qDebug() <<l_return;@ ?

            1 Reply Last reply Reply Quote 0
            • First post
              Last post