qtsignalssignals-slotsmetaobject

Qt trigger signal on all instances of a given class


Typically Qt signals are triggered on a specific instance of a QObject.

Is there a way to trigger it on all instances of a specific class via, perhaps, MetaObjects?

Or the only way is to maintain your own static list of all instances, perhaps by using constructors and destructors, and then just Q_FOREACH it?


Solution

  • How about creating a singleton behind the scenes, and connecting all your instances to a signal from that singleton (signal-to-signal connection)? When you want all your instances to emit the signal, just make the singleton emit it, and all instances will forward it.