I want to get a random pair with number n from my QHash.
Now I do it this way:
QHash<QString,QString>::iterator iterator = dictionary.begin();
iterator+= n;
question->setText(iterator.key());
But this seems just ridiculous... There must be a normal way. Can you help me please? I've read the whole entire man-page for QHash already
QHashdoesn't offer random selection. If you have to perform this operation often, then copy (pointers to) thekeys()of the hash table into avectororQVector, get a random index into that and use the key to look up the value in theQHash.Depending on what else you use the
QHashfor, you might want to convert it to a vector of pairs at some point and just use that for random selection.