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. [SOLVED] using toUInt on a QBytearray with a Sha3-Hashsum fails
QtWS25 Last Chance

[SOLVED] using toUInt on a QBytearray with a Sha3-Hashsum fails

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.1k Views
  • 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.
  • D Offline
    D Offline
    delok
    wrote on last edited by
    #1

    I am having a little problem right now which has left me puzzled for the past days.
    Unfortunately I didn't find any solutions in the forum for it:

    @QByteArray t_barr = (QCryptographicHash::hash(file.readAll(), QCryptographicHash::Sha3_512));

        qDebug() << "the size of the raw bytearray is: " << t_barr.size();
    
        quint64 result = t_barr.toUInt(&ok, 0);
    
        file.close();
    
        qDebug() << "Hash is "  << result << ok;
    
        return result;
    

    @

    This is the paste from the code-section that gives me trouble (all variables are defined. i left the debugging stuff in it).
    What I want is to cast the QBytearray with the Hash to a Uint or any other number-datatype.

    It does not work however.
    The Hash functions succeeds, the file can be opened in rw-mode, I can cast the Bytearray toHex without problem.
    The .size() tells me that the resulting Hash is 64 bytes long, shouldn't be a problem to store it.
    I tried using different datatypes for the cast, but every time the result is 0 and the
    @ bool ok

    @

    is set to false.

    I tried:

    • using a different hash algorithm

    • converting the result to base64 first

    • using int, quint, quint64, qulonglong, long, ...

    • specifying the base in .toUint(), tried 10, 0, and 16

    What could be the problem?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      A hash sum is not a mathematical sum, you don't end up with a number

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        delok
        wrote on last edited by
        #3

        Hi,
        thanks you for your quick response.

        That explains a lot.

        I guess I will be returning the QBytearray raw then, instead of converting it.

        I would say that this solves my problem.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          There's really no conversion needed, it's the data you need for other processing like comparing two files that should be the same.

          Happy coding !

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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