Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Beginner question on signals and slots.
mstoth last edited by
I have been searching but can not seem to find the answer to this simple question.
How do you connect a slot in a dialog to a signal from a different dialog when they are instantiated from different places?
I have a dialog A which creates a dialog B. This dialog B then creates dialog C. All three are instances of different classes.
I want to connect a signal from C to a slot in A but when I create C from B, C knows nothing of A and when I create B from A, A knows nothing of C.
I don't want to use globals. I feel there must be a simple way to do this but I'm just not getting it yet.
so in A, I can't do connect(C, SIGNAL(s1()), this, SLOT(s1())) because I don't have the C dialog created yet,
and in C, I can't do connect(this, SIGNAL(s1()), A, SLOT(s1())) because C doesn't have a pointer to A.
Thanks for any help!
- define in signal in B
- Connect signal in C in to Signal in B(make signal to signal)
- Connect signal in B to Slot in A
In general objects should be available to connect. You can make chain of signal/slots like the one explained above.
mstoth last edited by mstoth
Thanks. I didn't think of chaining the signals and slots. One solution I did find was to do a search for all open widgets in the application and select the one that matches the intended destination. This works but perhaps chaining the signals and slots would be more elegant.
Is the chaining approach considered the best practice generally?
@mstoth Yea typically chaining is how you would do that. That's how I've always done it.
The lazier way is to pass a pointer from dialog A down to dialog C so you can use it for your signals/slots. That method of course creates an interdependence that you typically don't want in your code though. :)
HafsaElif last edited by HafsaElif
This post is deleted!