Results 1 to 6 of 6

Thread: Syncronize Threads

  1. #1
    Join Date
    May 2006
    Posts
    57
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Syncronize Threads

    In one thread calculate an approach to one curve, and in certain steps drawing the current curve and continue calculating, I emit a signal when I want draw this curve, I put a debug message to see the process to draw, like this:

    Qt Code:
    1. Thread::ProcessX()
    2. {
    3. ...
    4. qDebug()<<"Draw";
    5. emit draw();
    6. qDebug()<<"Stop";
    7. ...
    8. }
    9. 77(signal send to DrawProcess() in the interface
    10. Interface::DrawProcess()
    11. {
    12. qDebug()<<"Now";
    13. ...
    14. }
    To copy to clipboard, switch view to plain text mode 

    When I run the program, in the terminal i see this:
    Qt Code:
    1. Draw
    2. Stop
    3. Now
    4. Draw
    5. Stop
    6. Draw
    7. Stop
    8. Draw
    9. Stop
    10. Now
    11. Now
    12. Now
    To copy to clipboard, switch view to plain text mode 

    What's up?

    Please Help
    P.D. Sorry for my bad english

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Syncronize Threads

    What kind of connection do you use? Is it a queued one?

  3. #3
    Join Date
    May 2006
    Posts
    57
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Syncronize Threads

    I use Siganls/slot with connect, in the thread have a signal and in the interface a slot.

    I don't know what kind of connection I used

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Syncronize Threads

    Quote Originally Posted by avis_phoenix View Post
    I don't know what kind of connection I used
    So you have used the automatic connection and in this case it should behave as queued connection. This means that the signal will be stored in receiver's event queue until it processes it. If there are other events to process in that queue, signal delivery will be deferred. And this might cause observed behavior.

  5. The following user says thank you to jacek for this useful post:

    avis_phoenix (6th September 2008)

  6. #5
    Join Date
    May 2006
    Posts
    57
    Thanks
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Syncronize Threads

    Thanks you so much then I will use Qt:irectConnection

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Syncronize Threads

    Quote Originally Posted by avis_phoenix View Post
    then I will use Qt::DirectConnection
    This isn't a good idea. With direct connections the code will be executed withing the thread that emits the signal.

    Take a look at QWaitCondition.

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51
  2. Threads...
    By Abc in forum Qt Programming
    Replies: 1
    Last Post: 19th June 2008, 17:35
  3. Once more: Threads in Qt4
    By high_flyer in forum Qt Programming
    Replies: 5
    Last Post: 9th August 2006, 18:35
  4. [QT4] threads, signals, and slots, please help.
    By ucntcme in forum Qt Programming
    Replies: 12
    Last Post: 25th January 2006, 14:23

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.