Results 1 to 2 of 2

Thread: Performance problem with QFile.

  1. #1
    Join Date
    Mar 2014
    Posts
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

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

  2. #2
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Performance problem with QFile.

    use the http://doc.qt.io/qt-4.8/QCryptographicHash::addData(), instead QCryptographicHash::hash(),

    Qt Code:
    1. #include <QCryptographicHash>
    2. #include <QFile>
    3. #include <QDebug>
    4.  
    5. int main()
    6. {
    7. QCryptographicHash crypto(QCryptographicHash::Md5);
    8. QFile file("linuxmint-16-xfce-dvd-64bit.iso");
    9.  
    10. if ( !file.open(QFile::ReadOnly) ){
    11. qDebug() << "ERROR: cant read file";
    12. }
    13.  
    14. qint64 size = 4 * 1024 * 1024; // segment of 4MB
    15. int iter = 0;
    16. while(!file.atEnd()){
    17. crypto.addData(file.read(size));
    18.  
    19. ++iter;
    20. qDebug() << "iteration #" << iter
    21. << " data offset; " << size*iter << "(bytes)" ;
    22. }
    23.  
    24. QByteArray hash = crypto.result();
    25. qDebug() << hash.toHex();
    26. return true;
    27. }
    To copy to clipboard, switch view to plain text mode 

    i test this minimal example, only replace the filepath
    Last edited by ecanela; 26th April 2014 at 18:52.

Similar Threads

  1. Replies: 2
    Last Post: 6th May 2013, 08:06
  2. QFile reading problem
    By giblit in forum Qt Programming
    Replies: 6
    Last Post: 5th April 2013, 05:45
  3. Problem with QFileDialog and QFile
    By Basti300 in forum Newbie
    Replies: 2
    Last Post: 26th May 2010, 20:18
  4. Problem with QFile
    By viciv919 in forum Newbie
    Replies: 5
    Last Post: 17th March 2010, 16:04
  5. QFile::atEnd() problem?
    By lvi in forum Qt Programming
    Replies: 9
    Last Post: 6th August 2008, 12:37

Tags for this Thread

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.