Results 1 to 2 of 2

Thread: Best Way to Poll for a Flag in Main Event Thread

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,330
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Best Way to Poll for a Flag in Main Event Thread

    Instead of setting a flag, have the slot emit a master "completed" signal when all of the threads have finished. Connect this signal to some other slot that then processes the composite results of the threads. No polling is needed.

    Of course, you have protected your main thread slot with a mutex or some similar mechanism to ensure that two threads don't attempt to update the status at the same time, right?

    --- Edit

    This last point (on a mutex) may not actually be a requirement. You should probably consult the Qt docs on threading and on signals and slots. In particular, connections between signals and slots across threads should be made as Queued Connections. In that case the slot will be thread safe, since signals will be queued for handling as they are received.
    Last edited by d_stranz; 23rd January 2020 at 17:49.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  2. The following user says thank you to d_stranz for this useful post:

    leinad (23rd January 2020)

Similar Threads

  1. Replies: 1
    Last Post: 10th May 2018, 08:58
  2. Replies: 0
    Last Post: 7th December 2017, 18:33
  3. Replies: 5
    Last Post: 22nd June 2012, 16:40
  4. Replies: 5
    Last Post: 8th February 2012, 09:56
  5. Main Thread Event loop
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2007, 12:10

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.