Unsolved QTcpServer across threads
-
I created a QTcpServer server in the main thread, and connect the readyRead() signal to a worker object in anther thread, however, once I access the server, there will be an warning like that socket notifiers cannot be enabled from another thread, I can't figure out some questions as follows:
- Why it happens? from google I know that QTcpSocket must be created and accessed in the same thread, but if so, why did not the official doc point it out, and how am I supposed to know these information so I can dodge these problems.
- The only doc I find related has a statement:
Event driven objects may only be used in a single thread. Specifically, this applies to the timer mechanism and the network module. For example, you cannot start a timer or connect a socket in a thread that is not the object's thread.
and I don't know what it means by "event driven objects"
4. I also want to know more about qt multi-thread programming, can you recommend some books or sites(I have already read the docs over and over, but it seems of little help)Thank you!
-
from google I know that QTcpSocket must be created and accessed in the same thread
This is not the case
Have a look at this example: https://wiki.qt.io/WIP-How_to_create_a_simple_chat_application