Hi everyone,

I need some help with this problem I have... I'm trying to make a worker thread perform a long operation and have the GUI stay responsive. I need to give the thread a chunk of data to work on and let it run. I've read that the best way to pass data inbetween threads is signals and slots, so what I did is I subclassed a QThread like this (slightly simplified example: the thread gets a vector of floats and returns an image):

Qt Code:
  1. class Worker : public QThread
  2. {
  3. Q_OBJECT
  4. public:
  5. void run();
  6. signals:
  7. void done(QImage);
  8. public slots:
  9. void makeImage(std::vector<float>);
  10. };
  11.  
  12. void Worker::run()
  13. {
  14. exec();
  15. }
To copy to clipboard, switch view to plain text mode 

The run() function just launches the event loop and at the end of makeImage slot I call exit(), I only need it to process the one signal. When the thread is done working it passes the result with the "done" signal. The vector type is registered with qRegisterMetaType() so it can be used with QueuedConnection.

Now the (possibly) problematic code:
Qt Code:
  1. Worker* worker = new Worker();
  2. connect(this, SIGNAL(makeImage(std::vector<float>)), worker, SLOT(makeImage(std::vector<float>)), Qt::QueuedConnection);
  3. connect(worker, SIGNAL(done(QImage)), this, SLOT(newImage(QImage)), Qt::QueuedConnection);
  4. worker->start();
  5. emit makeImage(my_vector);
To copy to clipboard, switch view to plain text mode 

I call for QueuedConnection explicitly to make sure the slot is called from the new thread.
The problem is: it doesn't seem like a new thread is started at all, the GUI is blocked and when I call QThread::currentThread() from the working function, the result is the same as from the GUI thread! How come it's not spawning a new thread to do the work? If what I'm doing can be done better please tell me.