As the topic suggests, I'm looking for the best way to send data from the main window GUI thread to a processing thread.

At the moment, the run() function in the ProcessingThread looks something like this:
Qt Code:
  1. void ProcessingThread::run()
  2. {
  3. while(1)
  4. {
  5. frame=grabFrame();
  6. if(flag1)
  7. doProcessingOnFrame1(frame,setting1,setting2);
  8. if(flag2)
  9. doProcessingOnFrame2(frame,setting3,setting4);
  10. if(flag3)
  11. doProcessingOnFrame3(frame,setting5,setting6);
  12.  
  13. emit newFrame(frame);
  14. }
  15. }
To copy to clipboard, switch view to plain text mode 

MainWindows.cpp has:
Qt Code:
  1. // Create queued connection between processing thread (emitter) and GUI thread (receiver/listener)
  2. connect(controller->processingThread,SIGNAL(newFrame(QImage)),this,SLOT(updateFrame(QImage)),Qt::QueuedConnection);
To copy to clipboard, switch view to plain text mode 

and also:
Qt Code:
  1. void MainWindow::updateFrame(const QImage &frame)
  2. {
  3. // Update public "flags" and "settings" members in ProcessingThread
  4. updateData();
  5. // Display frame in main window
  6. frameLabel->setPixmap(QPixmap::fromImage(frame));
  7. } // updateFrame()
To copy to clipboard, switch view to plain text mode 

Eveything works perfectly

However, at the moment I am updating/changing the "flags" and "setting" variables contained within the ProcessingThread by making them public and then altering them within updateFrame() in MainWindow.cpp (see above). This is merely my attempt update them "synchronously" after each loop of run() - so that they don't change in the middle of the execution of run() and thus erroneousness turn on more image processing than that actually set by the user.

However, it is my understanding that run() does not block when emitting the newFrame signal in the case of a queued-connection - thus the data update is not truly synchronous.

There has to be a better way to do change these variables in response to GUI events in MainWindow.

Here is a method I was thinking of:

Create a binary semaphore (initialized to 1) and use it like so in run():

GLOBAL: sem = new QSemaphore(1);

Qt Code:
  1. void ProcessingThread::run()
  2. {
  3. while(1)
  4. {
  5.  
  6. frame=grabFrame();
  7.  
  8. sem->acquire();
  9. if(flag1)
  10. doProcessingOnFrame1(frame,setting1,setting2);
  11. if(flag2)
  12. doProcessingOnFrame1(frame,setting3,setting4);
  13. if(flag3)
  14. doProcessingOnFrame1(frame,setting5,setting6);
  15. sem->release();
  16.  
  17. emit newFrame(frame);
  18. }
  19. }
To copy to clipboard, switch view to plain text mode 

And then merely use this global semaphore in the updateFrame() slot in MainWindow:
Qt Code:
  1. void MainWindow::updateFrame(const QImage &frame)
  2. {
  3. // Update public "flags" and "settings" members in ProcessingThread
  4. sem->acquire();
  5. updateData();
  6. sem->release();
  7. // Display frame in main window
  8. frameLabel->setPixmap(QPixmap::fromImage(frame));
  9. } // updateFrame()
To copy to clipboard, switch view to plain text mode 

However, this method again relies on making the "flags" and "settings" variables PUBLIC in ProcessingThread...

Is there a better way?

I'm open to and would really appreciate any suggestions
(If I have omitted any crucial information, please let me know.)

Thanks in advance to anyone who could help me with this!