Qt6 topics merged with General

qHash in Qt5

  • I have just migrated a project from qt4.8.5 to qt5.4.1, and it appears that the resulting value of a call to qHash() in qt4.8.5 to qt5.4.1 return different results. For example:

    qHash ( "Hello" ) in qt4.8.5 returns a different result to the same function call in qt5.4.1.

    Can someone please advise on this?


  • Hi htettey,

    QHash is a template class for storing key, value pairs. The hash returned by qHash() is used for fast lookup and can change in every version of Qt. It´s not intended to be used as a hash to store a password for example.
    If you want to have a hash of e.g. a QStringuse the QCryptographicHash class. You can choose the hash function to use.

    QCryptographicHash hashObject(QCryptographicHash::Sha256);
    QByteArray hashResult(hashObject.result());

  • @sneubert

    Hi sneubert,

    thanks very much for your reply. I was using it is store passwords which has now caused problems for me. I will do as you have recommended.

    Thank you.

Log in to reply