You cannot use QTcpSocket
from two different threads, because QObject
s are not thread-safe.
You've created your QTcpSocket
in the first task, so it "lives" in the thread associated with that task. If you pass its pointer into another QRunnable
, then a second thread will try to access it, which will break things.
You'll need to redesign your app in a way that doesn't share the same QTcpSocket
between different threads. One possibility is to implement different specific functions in your original task, and simply select the appropriate function based on the first received byte