Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using QNetworkAccessManager to upload files to Google drive. After uploading about 1300 files I get the following error:

C#
critical: Qthread::start:failed to create thread (the access code is invalid)


I am not explicitly using any QThread besides the main thread.

I am using QT 5.7.0

What I have tried:

I only use one instance of QNetworkAccessManager. I am also using about 4 QTimer instances to display a clock and initiate tasks (Display time, hide the window after some time, and show bubble messages)

Any help is appreciated.
Posted
Updated 2-Aug-16 21:41pm
Comments
Richard MacCutchan 3-Aug-16 2:54am    
It is most likely called inside the QT library.
Member 12562336 3-Aug-16 3:15am    
Thank you.

Since you are familiar with QT, do you have any idea why this message is being sent from QT Library?
Richard MacCutchan 3-Aug-16 3:21am    
I know nothing about QT. But if you are using the QT library and get an error referring to qthread, then it is a safe bet that it is something to do with that library.
Member 12562336 3-Aug-16 3:28am    
Sure. I knew that it was coming from the Library because there no such message was issued from my codes.

It is a run time message not from Windows because because Windows does not have a knowledge of QT.

But I thank you. I think I have an idea on how to solve it. It seems that a lot of threads were created to handle the REST API calls to send the packets to Google Drive. All those threads have been marked to be deleted, but still occupy memory.

I believed that they are all attached to the QNetworkAccessManager. So I am going to delete and recreate the QNetworkAccessManager. I thing it is going to take care of this problem.

1 solution

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).
 
Share this answer
 
Comments
Member 12562336 3-Aug-16 12:31pm    
Thank you. I will make sure resources are release4 at the right place.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900