假设只有main线程和子线程child

class child :public QThread
{
    Q_OBJECT
public:
    child ( QThread* parent = nullptr ){
    moveToThread ( this );
}

virtual void run (){
    exec ();
}

public slots :
    void Recv( LPVOID param ){
         int i = 0;
    }
};

1. Recv默认是在main中执行,要想使Recv在child中执行,只需在child 构造函数中加一句

moveToThread ( this );

2. 还有种方法是子类化一个QObject对象,然后把对象move到child中:

class obj:public QObject
{
    Q_OBJECT

public slots :
    void RecvParam ( LPVOID param ){
        int i = 0;
    }

};

child* thd = new child;
obj Obj;
Obj.moveToThread ( thd );
thd->start ();

欢迎讨论

11-14 21:49