The error
Qthread::start:failed to create thread (the access code is invalid)
occurs when trying to create a new thread while there are too many actually running.
QThreads
are used internally to perform the network operations. Each
QNetworkAccessManager
function that creates a connection (e.g.
get()
and
post()
) will create a new thread to perform the communication in the background.
If you create multiple connections at the same time a lot of resources are required. Each thread has it's own stack which size is linker and system specific (AFAIK Microsoft has a default of 1 MiB and GCC of 2 MiB).
To avoid creation of too many threads,
QNetworkAccessManager
will queue requests but only for identical hosts:
Note: QNetworkAccessManager queues the requests it receives. The number of requests executed in parallel is dependent on the protocol. Currently, for the HTTP protocol on desktop platforms, 6 requests are executed in parallel for one host/port combination.
So you might get out of resources if you connect to different hosts. A solution would be implementing your own queue to limit the number of active connections.
Another reason for the error may be that the reply objects are not deleted. Ensure that they are deleted after having been handled (use
deleteLater()
when doing that from within a signal handler).