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



  • 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?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

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



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


  • Lifetime Qt Champion

    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 !


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.