Results 1 to 5 of 5

Thread: Search value in QList

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Search value in QList

    1. This is QList<double> not QList<int>.
    2. If you can not sort the list then you have to check each element and choose the one for which abs (value) is the smallest. If you only have positive values, you choose the smallest value (you do not need abs). Something like this (for positive only value) :
    Qt Code:
    1. double s_value = list.at(0);
    2. int s_index=0;
    3. for(int i=1; i < list.size();i++)
    4. {
    5. if(list.at(i) < s_value)
    6. {
    7. s_value = list.at(i);
    8. s_index = i;
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to Lesiok for this useful post:

    pelaoqlo (6th February 2019)

Similar Threads

  1. Replies: 1
    Last Post: 14th November 2012, 21:00
  2. Qlist<QLabel *> in Qlist<QAction*>
    By Naahmi in forum Qt Programming
    Replies: 1
    Last Post: 9th September 2011, 08:53
  3. Fast QList search/access
    By tryinghard in forum Newbie
    Replies: 4
    Last Post: 15th January 2011, 02:00
  4. Replies: 4
    Last Post: 20th August 2010, 13:54
  5. BEst way to search QList for item
    By steg90 in forum Qt Programming
    Replies: 11
    Last Post: 18th July 2007, 09:41

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.