Timers cannot be ####### from another thread
-
And that is the issue. You are thus creating your socket in the main thread as well.
-
@SGaist , sorry, I'm not sure why you say that, the class clsMsgSender is not a socket. If you mean that:
mpsckClient = new QTcpSocket(this);
Is that the problem? because this is in the clsMsgSender constructor, then please explain what I should do because I suggested moving it into the thread and the response was no.
Can you please clarify what I'm doing wrong and how to fix it?
-
@SPlatten said in Timers cannot be ####### from another thread:
new QTcpSocket(this);
This creates an object with the parent in the main thread. And since a child must be in the same thread as the parent...
Don't pass this as parent and delete it by your own. -
@Christian-Ehrlicher for sockets you have to go one step further and ensure it's created in the thread that will actually use it.
-
@Christian-Ehrlicher for sockets you have to go one step further and ensure it's created in the thread that will actually use it.
-
Start with the QThread. There are several other chapters linked from the details of the class.
@SGaist , I've just read the details on QThread and I didn't see anything specifically regarding the use of Sockets. I then found this when searching online:
https://forum.qt.io/topic/57753/qtcpsocket-and-qthread
Obviously you are familiar with this one.https://stackoverflow.com/questions/34641732/qtcpsocket-handling-in-another-qthread
Not sure what the conclusion of the above was...https://www.bogotobogo.com/Qt/Qt5_QTcpServer_Multithreaded_Client_Server.php
Working through this....I must say the approach the last link takes is exactly the way I started, with sub-classing my listening class from QTcpServer, however after several posts here advising not to do this I changed my class.