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
    Qt products
    Qt5
    Platforms
    MacOS X Windows
    Thanks
    5

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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
  •  
Qt is a trademark of The Qt Company.