How to broadcast a signal in Qt4

I want a paradigm in Qt4 (PyQt4), where a component is able to respond to a signal without knowing anything about where it came from.

My internal reading suggests that I should explicitly connect the signals to the slots. But I want any of several components to be able to send a signal and process it with another component.

Comparing with other tools, for example, in wxWidgets I will use events. They are automatically distributed from child windows / objects to parents. At each level they can be processed. This means that if I have many children who can emit the same event, I do not need to explicitly associate them with the handler. I can just put the handler in the parent or some higher level in the window hierarchy. This means that only the event generator and the consumer should know about the event in general. The consumer does not need to know where the source of the event is, how many such sources are there or something else.

Is this possible in Qt - is there a different approach? Maybe there is an alternative event mechanism for signals and slots?

+3
source share
3 answers

This is not easy - you need to know something about the signal object and the receiving object to connect the two. However, depending on what you need, you can create a class that mediates between them (so that objects with signals tell the class that they exist and have such and such a signal, and objects with slots tell the class they exist and have such this is such a slot for connecting to this signal, and the intermediary class monitors both of them, making connections when necessary).

+1
source

Don't you need a good old-fashioned calling method? The answer is only the return value of the method.

0
source

, ( ) , . , . .

0

Source: https://habr.com/ru/post/1755432/


All Articles