Hi,

I've got a 3rd party blocking library that i'm trying to implement into my QT GUI application. Using a QThread, signals and slots, but i'm struggling to work out the best way to do things.

The library contains a number of different API calls which I will want to call at various points, and then return the reult to the main GUI thread.

So far I've created a class as follows

Qt Code:
  1. class LibraryManagerThread: public QThread
  2. {
  3. Q_OBJECT
  4. public:
  5. LibraryManagerThread();
  6. ~LibraryManagerThread();
  7.  
  8. protected:
  9. void run();
  10.  
  11. signals:
  12. void done(); // Signal back to main GUI thread when work is done.
  13.  
  14. private slots:
  15. /* place slots for each blocking api call here */
  16. };
To copy to clipboard, switch view to plain text mode 

In the class code I have the following :-

Qt Code:
  1. LibraryManagerThread::LibraryManagerThread()
  2. {
  3. // We have to do this to make sure our thread has the
  4. // correct affinity.
  5. moveToThread(this);
  6.  
  7. start();
  8. }
  9.  
  10. void LibraryManagerThread::run()
  11. {
  12. // This starts the event loop.
  13. exec();
  14. }
To copy to clipboard, switch view to plain text mode 

So the event loop will process any events I pass to it. So what i'm thinking is to signal from the main event loop to this thread, and then signal back to the main event loop once the work has been done.

However, i'm wondering how best to make this code portable, because using my method above, the LibraryManagerThread needs to know about the signals i am going to emit from the main GUI thread, hence it would then require code changes to use this class in a different application.

any thoughts how i could get around this?

cheers,

David