what you are saying is that i must not make calls to the QTcpSocket object's methods (that works in the QThread thread) with my main thread.
Well, that's logical.
thanks
what you are saying is that i must not make calls to the QTcpSocket object's methods (that works in the QThread thread) with my main thread.
Well, that's logical.
thanks
No, the problem is that part of the code that you think that runs in the thread does in fact not run in the thread.
All the code in the slot uses the main event loop while all the code in the run() function uses the thread event loop.
There are two ways to solve this:
1. As suggested, do not use threads.
2. Use threads correctly.
The last part is, for example, done by putting all your socket handling code in a separate QObject subclass.
Then move the object to a new thread. This way you're sure that the code in the slot also uses the thread event loop (because the complete object is moved to the thread).
Hi,
You could look at the fortunecookie server and client examples.
In that example the length of the "packet" is put upfront. On the receiving side, the length is read, and they keep on receiving until all the bytes are received. This is what you want.
It is best to see a TCP connection as a 'stream' of bytes that are coming in. You have to find the start and end of your 'message' yourself.
Best regards,
Marc
Oops... didn't go to the very last page of this thread. Well, better safe then sorry...
yeah, i think i'll just use threads correctly. I didn't understand well.
Bookmarks