Results 1 to 8 of 8

Thread: Occurrence Delay in qtconcurrent therds

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Occurrence Delay in qtconcurrent therds

    QtConcurrent takes a thread from a thread pool. The size of the pool is equal to the number of cores/cpus in your machine. Thus if you run your three-thread code on a less-than-three-core machine (once you correct all the issues mentioned later), it will never complete. The other issue is that you are using signals and slots and incorrectly assuming the slots will be run in the context of threads running the function that emitted the signal. Moreover you assume your timers will fire in the context of the threads running the start() function -- they will not since you don't have an event loop running for each of those threads and timers need events to be handled. Thus your code will do practically nothing apart starting three timers returning immediately (effectively finishing those threads).
    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.


  2. #2
    Join Date
    Oct 2010
    Location
    Iran
    Posts
    27
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Occurrence Delay in qtconcurrent therds

    Thanks
    Not enogh time to learn and use QThread , Possible to increase the 'thread pool' size ?
    Is there another solution ØŸ

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

    Default Re: Occurrence Delay in qtconcurrent therds

    Increasing thread pool size will not do you any good. That's the least of your problems. Learn to use QThread properly.

    Qt Code:
    1. QThread *thread = new QThread(this);
    2. thread->start();
    3. MyObject *obj = new MyObject;
    4. obj->moveToThread(thread);
    5. QMetaObject::invokeMethod(obj, "doSomething", Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 
    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.


  4. #4
    Join Date
    Oct 2010
    Location
    Iran
    Posts
    27
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Occurrence Delay in qtconcurrent therds

    Quote Originally Posted by wysota View Post
    Increasing thread pool size will not do you any good. That's the least of your problems. Learn to use QThread properly.

    Qt Code:
    1. QThread *thread = new QThread(this);
    2. thread->start();
    3. MyObject *obj = new MyObject;
    4. obj->moveToThread(thread);
    5. QMetaObject::invokeMethod(obj, "doSomething", Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 
    QObject::moveToThread: Widgets cannot be moved to a new thread

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

    Default Re: Occurrence Delay in qtconcurrent therds

    QObject::moveToThread: Widgets cannot be moved to a new thread
    That's definitely true. That's why you need to learn to use threads (regardless if you do it with QtConcurrent or with QThread) instead of blindly trying things. At least read the docs for multithreading with Qt.
    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. To add delay
    By vinayaka in forum Newbie
    Replies: 0
    Last Post: 3rd June 2011, 13:21
  2. Add Delay.
    By Johncdy in forum Qt Programming
    Replies: 1
    Last Post: 16th March 2011, 08:18
  3. Delay DLL loading ?
    By black_coder in forum Qt Programming
    Replies: 1
    Last Post: 2nd December 2009, 00:00
  4. QTimer delay
    By dima in forum Qt Programming
    Replies: 3
    Last Post: 2nd October 2009, 13:31

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.