qt信号和槽

类定义时:

 

class A {

Q_SIGNALS:
void syncinitApp(NQIntent *pIntent );

private Q_SLOTS:
void onSyncinitApp(NQIntent *pIntent );

}

 

 

可在构造函数中进行:

connect(this, SIGNAL(syncinitApp(NQIntent *)), this, SLOT(onSyncinitApp(NQIntent *)));

 

可在析构函数中进行:

disconnect(this, SIGNAL(syncinitApp(NQIntent *)), this, SLOT(onSyncinitApp(NQIntent *)));

 

可在需要跳转处:

emit syncinitApp(pNQIntent);

 

 

其实还有第五个参数:

connect(Sender,SIGNAL(signal),Receiver,SLOT(slot),Qt::DirectConnection);

 

第五个参数代表槽函数在哪个线程中执行 : (队列连接 = 异步)
1)自动连接(AutoConnection),默认的连接方式,如果信号与槽,也就是发送者与接受者在同一线程,等同于直接连接;如果发送者与接受者处在不同线程,等同于队列连接。 
2)直接连接(DirectConnection),当信号发射时,槽函数立即直接调用。无论槽函数所属对象在哪个线程,槽函数总在发送者所在线程执行,即槽函数和信号发送者在同一线程 
3)队列连接(QueuedConnection),当控制权回到接受者所在线程的事件循环时,槽函数被调用。槽函数在接受者所在线程执行,即槽函数与信号接受者在同一线程

posted @ 2018-07-23 17:50  聪明不绝顶  阅读(517)  评论(0编辑  收藏  举报