Performance problem with QFile.

  • I'm trying to calculate the hash of some disk image files (.iso)
    so i have to read the entire file and store it in QByteArray to pass it later to QCryptographicHash::Hash
    the problem is with reading performance, it takes a lot of time and the system freeze while using QFile::readAll() and storing it in byte array.
    is there any solution to reduce the time and prevent the system form freezing?

  • Moderators

    Use the stream operators. QCryptographicHash has an API that works with streaming QIODevices, too.

  • can you write a small piece of code :)

  • Try like this:

    @/max bytes to read at once/
    static const qint64 CHUNK_SIZE = 4096;

    /init hash/
    QCryptographicHash hash(Sha1);

    /open file/
    QFile file("");
    if (!

    /process file contents/
    QByteArray temp =;
    temp =;

    const QByteArray res = hash.result();
    qDebug("Hash is: %s", res.toHex());@

  • thank you, now it works times better :)

Log in to reply