Results 1 to 4 of 4

Thread: Qvector

  1. #1
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Qvector

    Hi ALL

    can any body help me by telling what will bw the Qt equivalent of std::vector.swap().

    Thank you all.
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qvector

    Take a look at QtAlgorithms.
    J-P Nurmi

  3. #3
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qvector

    Thanx. i went through the document. wat i found is qSwap() which can swap the tow passing element. but my requirment is replacement of std::vector.swap(vector element);
    i ve stored some values. like
    std::vector<int> vectelem;
    int a;
    int b;
    vectelem.push_back(a);
    vectelem.push_back(b);
    swap(vectelem);

    how to replace in Qt?
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qvector

    swap is not part of std::vector but is a separate algorithm. You can use it with QVector as well
    Qt Code:
    1. QVector<int> v;
    2. v.push_back(7);
    3. v.push_back(8);
    4. std::swap(v[0], v[1]);
    To copy to clipboard, switch view to plain text mode 

    By the way, I think your code is incorrect - you have to let swap() know which elements to swap. And you can use qSwap() as a replacement for swap().

    Or maybe you wanted to use std::reverse()?
    Qt Code:
    1. QVector<int> v;
    2. v.push_back(7);
    3. v.push_back(8);
    4. std::reverse(v.begin(), v.end());
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QVector Explosion
    By baray98 in forum General Programming
    Replies: 1
    Last Post: 11th November 2007, 15:12
  2. QVector and QSetting
    By mattia in forum Newbie
    Replies: 1
    Last Post: 8th November 2007, 16:21
  3. Memory allocation failure and crash in QVector
    By ashatilo in forum Qt Programming
    Replies: 16
    Last Post: 20th October 2007, 23:27
  4. QVector
    By sabeesh in forum Qt Programming
    Replies: 2
    Last Post: 17th September 2007, 14:37
  5. QVector QVarLengthArray speed question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 22nd January 2007, 09:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.