Results 1 to 3 of 3

Thread: Problem with qsrand and time(0)[SOLVED]

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Problem with qsrand and time(0)[SOLVED]

    At least, there is where I think I'm having a problem.

    I have the next code:

    Qt Code:
    1. QColor vColor[11] = {Qt::black, Qt::red, Qt::darkRed, Qt::darkGreen, Qt::blue, Qt::darkBlue, Qt::darkCyan, Qt::darkMagenta, Qt::yellow, Qt::darkYellow, Qt::darkGray};
    2. qsrand(time(0));
    3. int iRandomColor = (qrand() % 11);
    4. QColor myColor = vColor[iRandomColor];
    To copy to clipboard, switch view to plain text mode 

    This is a part of a function called by the constructor of a class, and I create two objects one after the other. But they always have the same color. BUT if I stop it (breakpoint or "Sleep"), the color is different.

    I think this could be because the qsrand is always choosing the same value, because it's executed at the same time (or pretty close), that's why it chooses a different color when I stop the execution.

    But I'm not sure... and, anyway, I don't know how I could solve that.

    any idea? thanks!
    Last edited by jano_alex_es; 17th July 2009 at 08:42.

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.