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. Performance problem with QFile.
Forum Updated to NodeBB v4.3 + New Features

Performance problem with QFile.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.0k Views 1 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.
  • A Offline
    A Offline
    Abdeljalil
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

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

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Abdeljalil
        wrote on last edited by
        #3

        can you write a small piece of code :)

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          Try like this:

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

          /init hash/
          QCryptographicHash hash(Sha1);

          /open file/
          QFile file("foo.bar");
          if (!file.open(QIODevice::ReadOnly))
          return;

          /process file contents/
          QByteArray temp = file.read(CHUNK_SIZE);
          while(!temp.isEmpty())
          {
          hash.addData(temp);
          temp = file.read(CHUNK_SIZE);
          }

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

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Abdeljalil
            wrote on last edited by
            #5

            thank you, now it works times better :)

            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