Results 1 to 6 of 6

Thread: Hash a file with QT

  1. #1
    Join Date
    Nov 2009
    Posts
    31
    Thanks
    5

    Default Hash a file with QT

    What's the best way to hash a file with QT?

    I'm looking at QCryptographicHash, but the only inputs it takes are either char* or QByteArray.

    Someone in another thread claims they managed to get this to calculate an MD5 on a file by passing in a path, but I'm not seeing that behavior:
    http://www.qtcentre.org/threads/2266...-make-md5-hash

    I could read in a QFile, and convert it to a QByteArray with readAll(), but that takes up as much memory as the size of the file. Is there a more memory efficient way to do this?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Hash a file with QT

    What's about qHash()?

  3. #3
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Hash a file with QT

    You can do it in two steps: read a block of file in bytearray, hash it, and append the result to another bytearray. When file reaches the end do hash over second bytearray

  4. #4
    Join Date
    Nov 2009
    Posts
    31
    Thanks
    5

    Default Re: Hash a file with QT

    Lykurg: I'm looking at QHash, and I'm not exactly sure how to go with this one. Is there a good way to hash a file with it?

    Borisbn: So is that the same MD5 that would be calculated in one step? So "abcdef" hash is the same as hash(hash("abc") + hash("def"))?

  5. #5
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Hash a file with QT

    You said:
    Quote Originally Posted by manekineko View Post
    I could read in a QFile, and convert it to a QByteArray with readAll(), but that takes up as much memory as the size of the file. Is there a more memory efficient way to do this?
    that's why I suggested to read file by small buffer. However hash( AB ) is NOT equal to hash( A ) + hash( B ). If it matter to you, don't do this way, but if not - IMHO it's quick decision.

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Hash a file with QT

    Quote Originally Posted by manekineko View Post
    Lykurg: I'm looking at QHash, and I'm not exactly sure how to go with this one. Is there a good way to hash a file with it?
    I didn't mean QHash. I said qHash (! case sensitive) wich is documented at the bottom of QSourceLocation.

Similar Threads

  1. How to get sha1 hash
    By lyuts in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2012, 15:35
  2. Replies: 6
    Last Post: 22nd March 2010, 08:57
  3. Basic hash problem
    By feraudyh in forum Newbie
    Replies: 6
    Last Post: 4th December 2009, 08:59
  4. Joomla 1.5 password hash Class 1.0 for QT using C++
    By RajabNatshah in forum Qt Programming
    Replies: 0
    Last Post: 6th October 2009, 15:49
  5. Are there functions to make md5 hash
    By learning_qt in forum Qt Programming
    Replies: 8
    Last Post: 22nd July 2009, 04:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.