- 论坛徽章:
- 0
|
我创建了两个线程,然后利用信号与槽函数进行两个线程之间的通讯,一个线程发送信号,另一个线程接收信号,但是槽函数接收不到信号!!
两个线程在主函数中已被初始化并启动start()了。
线程1:readthread
"readthread.h"
=============================
class readthread:public QThread
{
Q_OBJECT
public:
readthread();
~readthread();
virtual void run();
signal:
void signal_send_net(unsigned int);
}
=============================
readthread.cpp
=============================
readthread::readthread()
{
}
readthread::~readthread()
{
}
void readthread::run()
{
emit signal_send_net(12);
}
==============================
writethread.h
==============================
class writeThread:public QThread
{
Q_OBJECT
public:
writeThread();
~writeThread();
virtual void run();
public slots:
void slot_rcv_net(unsigned int);
private:
readthread *rth;
}
================================
writethread.cpp
================================
writeThread::writeThread()
{
}
writeThread::~writeThread()
{
}
void writeThread::run()
{
rth=new readthread();
connect(rth,SIGNAL(signal_send_net(unsigned int)),this,SLOT(slot_rcv_net(unsigned int)));
}
void writeThread::slot_rcv_net(unsigned int net)
{
qDebug()<<"net="<<net;
}
================================= |
|