Results 1 to 13 of 13

Thread: Randomization QList<QString> on label

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Randomization QList<QString> on label

    Either:

    Qt Code:
    1. std::shuffle(str_list.begin(), str_list.end());
    2. str_list.takeFirst();
    To copy to clipboard, switch view to plain text mode 

    or

    Qt Code:
    1. QString str = str_list.at(qrand() % str_list.size());
    To copy to clipboard, switch view to plain text mode 

    depending on the effect you want to achieve (the first guarantees the same string is not chosen twice in a row, the other does not).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    smemamian (2nd July 2013)

Similar Threads

  1. How to display the numbers in a QList<QString> ?
    By harish in forum Qt Programming
    Replies: 4
    Last Post: 3rd January 2012, 04:26
  2. I Want to sort QList<QMap<QString , qreal > >
    By amiref in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2011, 13:33
  3. QList < QHash < int, QString> > ... clear() is slow
    By JoZCaVaLLo in forum Qt Programming
    Replies: 8
    Last Post: 15th March 2011, 11:07
  4. Replies: 7
    Last Post: 16th August 2009, 09:03
  5. Replies: 0
    Last Post: 25th June 2009, 08:17

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.