Answer the question
In order to leave comments, you need to log in
How to correctly compose the qHash function for an object containing two QStrings? Or just what is the algorithm for hashing two strings?
You need to push a custom data type into the QSet, which consists of two QStrings, something like:
class Mynametype {
public:
QString firstName;
QString lastName;
};
"Abdul Karim Jabar"
, then { firstName="Abdul ", lastName="Karim Jabar" }
{ firstName="Abdul Karim", lastName=" Jabar" }
return qHash(firstName+"|"+lastName);
Answer the question
In order to leave comments, you need to log in
And why such a strange need for a UNIQUE hash (which by the way, in principle, you will not get for two lines of 20 characters, since the hash value is of the uint type)?
> these are DIFFERENT objects, despite the fact that the concatenation of firstName + lastName is equal.
well, let it match once, not such a frequent case for a first and last name. Will you have a thousand such Karims with the same concatenated name?
I did the same for myself as you did.
gluing, and between them a separator. works fast enough.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question