2
votes

My Setup: I have one class that only emits signals called class Conn.

All of my QObject classes (A, B, and C) exist in isolation and I don't want them to know about each other at all. However, if class A wants to send some information outside of itself, it must send a signal to the Conn object.

Class B and C both have the access to the Conn object and can themselves decided on whether or not they want to listen to one of Conn's signal.

My Problem: Let's say class A wants to emit the signal in the Conn object called sig_updateFoo(int) whenever it updates foo. Now, let's say class A also wants to connect the sig_updateFoo(int) signal to its slot called slot_FooUpdated(int) because it also wants to listen for when someone else emits the Conn object's signal.

A logical error occurs when when Class A has the Conn object emit a signal which is also connected to one of its slots.

I need to know if the original emitter was Class A (in which case I will disregard the call), or if it was a different class, which is ok).

Ideas I have tried: If I use QObject::sender() in Class A's slot, I only get a reference the Conn object, not Class A.

Any ideas?

1

1 Answers

2
votes

In general you would have to pass some form of identifier with each signal emission. The only functionality Qt offers you in this regard is sender(), but as you have found out, it only returns the last sender (unsurprisingly).

However, in this scenario wouldn't it be simpler to just compare the value received by slot_FooUpdated(int) to last one sent to the Conn object, and only act upon it if the values are different?