Answer the question
In order to leave comments, you need to log in
How can I make one QHash key have two keys, so that I can find a value using any known of them?
In general, subject.
In short, for what - for a model based on QAbstractItemModel
since. in it you need to give values by line, i.e. from 0 to N,
but I would like to leave the ability to find values not by string, but for example by ID
, for this I would like that there would be two keys in one QHash key and find the value by any known one.
for this, I don’t want to make two QHash that would still bother and make sure that both there and there are the correct values.
Answer the question
In order to leave comments, you need to log in
It's not very clear what you want to achieve. Can you provide an example of code that illustrates your problem and an example of how you are going to solve it (even if the code does not work)? Perhaps you are simply not working correctly with the model and view.
In any case, a hash (ordinary QHash) cannot be made two keys.
Make two Hashes, one normal, and in the second as a value - a pointer to the value from the second
I thought, why am I breaking my head with storing line numbers ... after all, they should always be from 0 to N without gaps.
And I use an iterator for this ... after all, you can add a value to the iterator and this will be similar to moving to the desired line. Only from here follows the only problem - if you need to rearrange the lines in the model, you need to somehow change where the iterator points (both the key and the value).
and find at QHash returns the iterator.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question