Hi all,

just need a hint from somebody.

I have several classes derived from QObject acting as some kind of "managers" with signals and slots. Each of this objects runs in its own thread. This way, it's easy to serialize signals by using queued signal/slots connections. Inside the objects, there is a QList which has to be protected by a mutex.

Something like this:
Qt Code:
  1. class ManagerThread : public QThread
  2. {
  3. Q_OBJECT
  4. public:
  5. ManagerThread( QObject * parent = 0 ) : QThread( parent ) {}
  6. protected:
  7. void run() { exec(); }
  8. };
  9. ...
  10. class XYManager : public QObject
  11. {
  12. Q_OBJECT
  13. QList<int> list;
  14. mutable QMutex* mutex;
  15. public:
  16. XYManager(void);
  17. QList<int> GetList() const {
  18. QMutexLocker locker(mutex);
  19. return listNamesProgInfo;
  20. };
  21. public Q_SLOTS:
  22. void initialize();
  23. void addToList(int a);
  24. Q_SIGNALS:
  25. void signal_ListChanged();
  26. };
  27.  
  28. ...
  29.  
  30. xy_manager = new XYManager(*this);
  31. threadXY = new ManagerThread();
  32. threadXY->start();
  33. xy_manager->moveToThread(threadXY);
To copy to clipboard, switch view to plain text mode 

Now I can e.g. invoke a slot either with QMetaObject::invokeMethod or with a signal/slot connection in xy_manager which performs some action with a queued connection.

So far, so good. But: if I want the thread which invokes the method in the manager to wait for completion of the method, how can I achieve that?

Something like
Qt Code:
  1. QMetaObject::invokeMethod(xy_manager, "initialize", Qt::BlockingQueuedConnection);
  2. // wait here until initialize has finished.
To copy to clipboard, switch view to plain text mode 

As far as I know, a BlockingQueuedConnection waits until the signal is delivered but not until the method has finished.
So, an idea might be to use a QWaitCondition. But: how do I wait for the condition? Does the manager has to make the QWaitCondition available then via a get-method? And further: Since several methods inside the manager access the list, I use a recursive mutex to avoid a deadlock inside the manager. As far as I understand, recursive mutexes don't work with QWaitConditions, right?

I am a bit puzzled on this one. Any help?

Thanks,

Rainer