Qt-interest Archive, April 2008
Signal slot problem.
Message 1 in thread
I have three objects: A, B, C. Now I do the following:
connect(A, SIGNAL(clicked()), B, SLOT(dosomething()));
connect(A, SIGNAL(clicked()), C, SLOT(show()));
connect(C, SIGNAL(clicked()), B, SLOT(dosomething()));
Basically the callings are:
A------> B;
A------->C--------->B;
Now the problem is that I want to make sure that the function dosomething()
is only called ONCE. Or if the signal from A is trigged and calls C, I don't
want the signal to trigger B anymore. How can I do that?
Thanks in advance
Dave.
Message 2 in thread
Hi,
"Dave Sun" <dave.sun.moon@xxxxxxxxx> wrote in message
news:f70a34d60804092101w1588c069n6a98be5144db60ca@xxxxxxxxxxxxxxxxx
> I have three objects: A, B, C. Now I do the following:
>
> connect(A, SIGNAL(clicked()), B, SLOT(dosomething()));
> connect(A, SIGNAL(clicked()), C, SLOT(show()));
> connect(C, SIGNAL(clicked()), B, SLOT(dosomething()));
>
> Basically the callings are:
> A------> B;
> A------->C--------->B;
>
> Now the problem is that I want to make sure that the function
> dosomething() is only called ONCE.
> Or if the signal from A is trigged and calls C, I don't want the signal to
> trigger B anymore.
> How can I do that?
Multiple options:
1) rethink your connections. There may be a way to avoid the double
connections
2) use a flag in your doSomething slot to only execute once.
3) disconnect the signals after executing of your slot. Look at
QObject::disconnect in the documentation.
4) ... (probably more options possible)
Good luck!
André
--
[ signature omitted ]