有两个问题,首先你这个TCPSocket收到指令了么,其次你这个次线程有没有自己的事件循环,如果你的次线程有自己的事件循环,则信号事件不走QApplication::exec()事件循环,那么信号相当于并没有发出来
moveToThread和QThread::run里调用exec可以创建线程自己的事件循环,如果信号要外发,则需要做一些转接操作。
Qt开发手册:
A QObject instance is said to have a thread affinity, or that it lives in a certain thread. When a QObject receives a queued signal or a posted event, the slot or event handler will run in the thread that the object lives in.
Note: If a QObject has no thread affinity (that is, if thread() returns zero), or if it lives in a thread that has no running event loop, then it cannot receive queued signals or posted events.
By default, a QObject lives in the thread in which it is created. An object's thread affinity can be queried using thread() and changed using moveToThread().
All QObjects must live in the same thread as their parent. Consequently:
setParent() will fail if the two QObjects involved live in different threads.
When a QObject is moved to another thread, all its children will be automatically moved too.
moveToThread() will fail if the QObject has a parent.
If QObjects are created within QThread::run(), they cannot become children of the QThread object because the QThread does not live in the thread that calls QThread::run().
Note: A QObject's member variables do not automatically become its children. The parent-child relationship must be set by either passing a pointer to the child's constructor, or by calling setParent(). Without this step, the object's member variables will remain in the old thread when moveToThread() is called.