Results 1 to 20 of 31

Thread: multi threading or QConcurrent for the scenario

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default multi threading or QConcurrent for the scenario

    Hi,

    I have a scenario where in I have to show a document on click of the document icon. Each page of the document is a separate html which is encrypted.
    Due to the huge number of pages, it take more time to decrypt all the html files and show the page.

    Kindly suggest which one is the best suitable (QThread / QConcurrent) , so that I can show the page once the 1st file is decrypted without waiting for all files to complete decrypting process. I want to make the page viewing and the decrypting happen simultaneously once the decrypting of the 1st file is done.

    Thanks in advance

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: multi threading or QConcurrent for the scenario

    As you don't need any background activity to be done continuously, it would be better to use QConcurrent, just run the decrypting function QtConcurrent::run().
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: multi threading or QConcurrent for the scenario

    Thanks for the quick response.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: multi threading or QConcurrent for the scenario

    I would rather put all pages into a container and use QtConcurrent::map().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2015
    Posts
    185
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: multi threading or QConcurrent for the scenario

    How do I use QtConcurrent::map()

    I have tried to implement QtConcurrent, but it crashes
    stating the below error
    "Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
    0 libsystem_kernel.dylib 0x00007fff8cb0f866 __pthread_kill + 10
    1 libsystem_pthread.dylib 0x00007fff87aee35c pthread_kill + 92
    2 libsystem_c.dylib 0x00007fff89f2fb1a abort + 125
    3 org.qt-project.QtCore 0x000000010c1a2159 qt_message_fatal(QtMsgType, QMessageLogContext const&, QString const&) + 9
    4 org.qt-project.QtCore 0x000000010c1a3611 QMessageLogger::fatal(char const*, ...) const + 161
    5 org.qt-project.QtCore 0x000000010c19e815 qt_assert_x(char const*, char const*, char const*, int) + 85
    6 com.yourcompany.learnOn 0x000000010b2cd880 QList<QFileInfo>:perator[](int) + 96 (qlist.h:486)
    7 com.yourcompany.learnOn 0x000000010b2cbf8a loadbook::decryptLoop(int, int) + 138 (loadbook.cpp:122)

    ASSERT failure in QList<T>:perator[]: "index out of range", file /Applications/QT/5.4/clang_64/lib/QtCore.framework/Headers/qlist.h, line 486
    The program has unexpectedly finished.


    The code is as below
    Qt Code:
    1. totalXHtmlPages = 173
    2. int index=0;
    3.  
    4. while( index <totalXHtmlPages)
    5. {
    6. if(stopThread) return;
    7.  
    8.  
    9. QFuture<QStringList> test = QtConcurrent::run(this,&loadbook::decryptLoop,index,index+13);
    10. PgContents.append(test.result());
    11.  
    12. index = index + 13;
    13. }
    14.  
    15.  
    16. QStringList loadbook::decryptLoop(int startIndex, int endIndex)
    17. {
    18. QStringList decryptContent;
    19. for(int index = startIndex; index < endIndex; index++)
    20. {
    21.  
    22. if(stopThread) break;
    23. decryptContent.append(decrypt->decryptFile(FileInfoList[index].absoluteFilePath(), 'A'));
    24. qDebug()<<"FileInfoList["<<index<<"] -> "<<FileInfoList[index].absoluteFilePath();
    25. }
    26. return decryptContent;
    27. }
    To copy to clipboard, switch view to plain text mode 
    Here I dont find multiple thread which I intended to create.

    how can I make this 173 files to be decrypted as fast as possible using threads
    Last edited by ejoshva; 6th March 2015 at 12:20.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: multi threading or QConcurrent for the scenario

    Your code makes no sense. You start a thread only to wait until it finishes executing. Use QtConcurrent::map() as advised.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Multi-threading
    By plopes21 in forum Qt Programming
    Replies: 6
    Last Post: 2nd January 2013, 17:45
  2. Slow Multi-Threading
    By AwDogsgo2Heaven in forum Qt Programming
    Replies: 5
    Last Post: 19th July 2009, 21:36
  3. Multi-threading
    By lixo1 in forum Qt Programming
    Replies: 5
    Last Post: 22nd June 2009, 13:22
  4. Multi threading ...
    By kiranraj in forum Qt Programming
    Replies: 2
    Last Post: 18th June 2007, 16:51
  5. Multi-threading
    By shamik in forum Qt Programming
    Replies: 15
    Last Post: 28th November 2006, 10:22

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.