Important: Please read the Qt Code of Conduct -

How does qHash(QStringRef&) work?

  • I'm curious as to how this method works. Is it just an overload that calls QStringRef::toString() (thereby making a copy of the referenced substring since this is how I'm using QStringRef) and passes that to qHash(QString&)? Or is it cleverer than that?

    I'd like to use this function, so I'd like to know if it does any copying.


  • Source:

    @uint qHash(const QStringRef &key)
    return hash(key.unicode(), key.size());

    Returns a Unicode representation of the string reference. Since the data stems directly from the referenced string, it is not null-terminated unless the string reference includes the string's null terminator.

  • Nice! Thanks!

Log in to reply