Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qHash in Qt5
Qt 6.11 is out! See what's new in the release blog

qHash in Qt5

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    htettey
    wrote on last edited by
    #1

    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?

    Thanks

    1 Reply Last reply
    0
    • sneubertS Offline
      sneubertS Offline
      sneubert
      wrote on last edited by
      #2

      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);
      
      hasObject.addData(QByteArray(QString("Hello").toStdString().c_str()));
      
      QByteArray hashResult(hashObject.result());
      
      H 1 Reply Last reply
      1
      • sneubertS sneubert

        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);
        
        hasObject.addData(QByteArray(QString("Hello").toStdString().c_str()));
        
        QByteArray hashResult(hashObject.result());
        
        H Offline
        H Offline
        htettey
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved