At least, there is where I think I'm having a problem.
I have the next code:
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};
qsrand(time(0));
int iRandomColor = (qrand() % 11);
QColor myColor
= vColor
[iRandomColor
];
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};
qsrand(time(0));
int iRandomColor = (qrand() % 11);
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!
Bookmarks