Do you call exec() in your run() method?
I.e. do you start the thread's event loop?
Cheers,
_
Do you call exec() in your run() method?
I.e. do you start the thread's event loop?
Cheers,
_
Thanks for your response.
The only exec() I call is when I exec the app from the main file.
The server_thread subclasses QThread, so after I construct it in the rtserver, I call:
I expected start() to exec the thread, no?
The run() function (which in this case is just an event loop) of the server_thread gets called. The first thing it does is use the raw socket descriptor it got in the c'tor to construct a QTcpSocket in itself (so it's part of the new thread), then it goes into an event loop handling requests from client, doing calculations, and writing data back to them. It is most definitely calling run() because the socket gets constructed (which is when it gives the warning now) and printing stuff out, etc. It's just not getting data from the socket anymore.
Since I overrode incomingConnection() in the server, I just pass the raw/native socket descriptor to the new thread and the new thread constructs the QTcpSocket around it...but the read/write doesn't seem to be working anymore and I'm not sure why... The old method called nextPendingConnection() in the original thread to get the QTcpSocket...then I passed that socket over to the server thread. Qt complained about this on the write() function saying that I shouldn't be writing to a QTcpSocket that is on a different thread, so I restructured it like this so that the QTcpSocket is constructed on the spawned thread.
Last edited by Syndacate; 14th October 2014 at 18:35.
Then you are missing it in the thread's run()
That starts the thread. The default implementation of run() calls exec() to start the thread's event loop.
Since you overwrote that, you have to start it either by calling the base implementation of run() or calling exec() yourself.
If you don't execute the thread's event loop then the thread will exit as soon as the run method's scope is done.
Cheers,
_
Bookmarks