发出信号时多次调用插槽 [英] slot is called multiple times when signal is emitted
问题描述
考虑如下功能:
class1::class1()
{
class3 obj3 = new class3(this);
}
void class1::function1()
{
class2 *obj2 = new class2();
connect(obj3, SIGNAL(sig()), obj2, SLOT(slt()));
}
void class3::function2()
{
emit sig();
}
我多次调用function1().function2()也被多次触发
I am invoking function1() multiple times. function2() is also triggered multiple times
我想要的是,每当发出sig()时,都应调用slt(),但实际上是,第一次发出sig()时,调用slt()的次数就是调用function1()的次数.下次调用sig()时,不会调用slt().如果有人可以帮助我实现这一目标,那将是一个很大的帮助.
What I want is, whenever sig() is emitted slt() should be called, but what's happening is, first time when sig() is emitted slt() is being called number of times function1() is invoked. Next time when sig() is invoked slt() is not called. It would be a great help, if somebody can help me achieve this.....
推荐答案
您应该只调用一次 connect
.将调用 connect
的代码移至仅调用一次的另一个函数.
You should only call connect
once. Move your code that calls connect
to a different function that is only called once.
这篇关于发出信号时多次调用插槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!