I have a QNetWorkAccessManager object created in thread 1 (main GUI thread).

Later, a different thread wishes to use it, like this:

Qt Code:
  1. QNetworkReply *reply = _manager->get(request_);
To copy to clipboard, switch view to plain text mode 

This results in the error message to console:
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QNetworkAccessManager(0x146a3c0), parent's thread is QThread(0x134f500), current thread is QThread(0x3261ca0)
I read about it, and find that I should not have the function get execute in the thread that the QNetworkAccessManager was not created in.

I then find that I can use moveToThread() to fix this. I add code:

Qt Code:
  1. _manager->moveToThread(QThread::currentThread());
  2. QNetworkReply *reply = _manager->get(request_);
To copy to clipboard, switch view to plain text mode 

This does not work, with the following error to console:
QObject::moveToThread: Current thread (0x2b44b20) is not the object's thread (0x134f500).
Cannot move to target thread (0x2b44b20)
I read up on moveToThread(), and I think the problem here is that I can only do this in the thread that the QNetworkAccessManager is in. That is, I have to run the function moveToThread() in the thread that the QNetworkAccessManager is currently "in", or "has affinity with", which is probably thread one (main GUI thread). I can push the QNetworkAccessManager from that original thread to the current thread, but I cannot pull it from the current thread.

At this point, this is starting to look like a lot of work and I think I must be missing something. There must be a better, "right" way to do this. To create a QNetworkAccessManager object in the main GUI thread and then use it from other threads. What am I missing? How is this meant to be done?