Multiple windows signal slot problem
-
connect only connects the signal and slots. You need to use the emit keyword to send the signal.
if the signal name is 'colorSelected' you should send the signal using
emit colorSelected(color)
Once you do this above slot will be called.
-
Hi and welcome to devnet,
Since "d" looks like it's created on the stack, are you sure it exists long enough to actually send the signal ?
Just to correct Dheerendra, you can also connect signals to signals. It's called signal forwarding. Not necessarily useful in this precise case but might be in the future.
-
Yes, Signal to Signal connect also can be used. What I meant in the above post was that, connect does not emit signal. It only connects. If he is assuming that it automatically emits signal it will be potential issue.
I think 'd' and 'bargraph' as stack variable are good observation from Galst. I feel this could be potential problem in your case. Make them as heap variables.
d = new classD
bargraph = new BarGraph. -
[quote author="Dheerendra" date="1389781569"]Yes, Signal to Signal connect also can be used. What I meant in the above post was that, connect does not emit signal. It only connects. If he is assuming that it automatically emits signal it will be potential issue.
I think 'd' and 'bargraph' as stack variable are good observation from Galst. I feel this could be potential problem in your case. Make them as heap variables.
d = new classD
bargraph = new BarGraph.[/quote]
Thanks a lot Dheerendra.
I checked the use of "emit" and wote
@emit d.colorSelected(bar_color);@But colorSelected(const QColor &) is a protected signal of QColorDialog. So it won't work if I wrote it in this way?
Could you please give me some further suggestions?Many thanks!
-
You can't emit a signal from another class
QColorDialog will emit the signal when needed
-
[quote author="SGaist" date="1389779303"]Hi and welcome to devnet,
Since "d" looks like it's created on the stack, are you sure it exists long enough to actually send the signal ?
Just to correct Dheerendra, you can also connect signals to signals. It's called signal forwarding. Not necessarily useful in this precise case but might be in the future.
[/quote]
Thank you very much SGaist! -
[quote author="SGaist" date="1389789056"]You can't emit a signal from another class
QColorDialog will emit the signal when needed[/quote]
Thanks a lot SGaist, it is because the "stack", I changed the position of the "connect" and it works now.
-
What do you mean by: "changed the position of the connect" ?
-
[quote author="SGaist" date="1389876303"]What do you mean by: "changed the position of the connect" ?[/quote]
Just right after the declaration of d
-
Looks like you might be doing something unusual with your code, can you post it ?