Answer the question
In order to leave comments, you need to log in
Is it possible to communicate with the parent thread from the child (threading)?
Is it possible to access the parent thread in the child thread and call something from it? Why do I need it? I decided to write a simple chat with a graphical interface. I used the socket module as a server, and took pyqt for the interface. I also used threading. What for? In order for my server to accept connections in a separate thread, i.e. be independent. When a message arrived, I added "\n" to it to force a line break. After that, I simply displayed this message in the textEdit field, after disabling the ability to change the text in this field. BUT. My interface was in the main thread, and I set the text from the child. Well, I got an error saying that this is not possible. I solved it with async, but still it got interesting, was it possible to simply call the setText method from the child (to write to the text in the field) and not bother with asynchrony? If so, how?
Answer the question
In order to leave comments, you need to log in
All GUI libraries are not thread-safe, so you cannot access interface components from threads. In such cases, the threads send signals to the main thread, which, based on these signals, performs actions with the interface.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question