How properly connect two widgets between two windows
-
I have a MainWindow with lots of MyLabels showing images.
And a SettingDialog with two buttons.
I want trigger some slot of MyLabel by clicking buttons in SettingDialog.
I tried use signal slot chain,that is ,when signal trig a slot,the slot do nothing but emit signal to upper layer.
Its bad idea,because it must ensure every connections is connect right on sig slot chain
And naming the signal slot pair also painful.
What's a proper or standard, clean way to connect two widgets between two windows, if widgets are private to each other?
Thank you.
-
@pachisuro4096 said in How properly connect two widgets between two windows:
I want trigger some slot of MyLabel by clicking buttons in SettingDialog.
There are many things to say and many possibilities for your question. But I pick this out. Why do you want to trigger widget slots from some other dialog anyway? If this is such an issue. think about exporting the required functionality as a public method of its own.
I will also just comment that inspecting Qt source code there are indeed examples where they spell out "redirecting" each signal of an object into another signal.
If widgets are so "private" to each other I am "surprised" external objects want to access them. The idea of private is that external things just don't need to do that. Else maybe they (or rather accessors) need exposing.
One last: depending on your requirements, you might be interested in QSignalMapper Class as an approach to reducing the number of distinct signals to deal with.