Why don't you just use one dedicated QObject subclass as the message bus? There you define all the signals that can be exchanged for the message bus, and you provide the appropriate notification methods that emit these signals. Now every component that wants to receive “messages” can connect to the signals of interest.
If you want a more general method to use the same approach as before. However, the subclass of the (singleton) QObject class now has only the message (QByteArray) signal and the sendMessage (QByteArray) public method that emits this signal. You might want to declare the method of sending the message as a slot, just in case you want to connect another signal to the sending method.
I use these approaches myself and they work great. Even different threads can interact with each other using this mechanism without any problems. If you use the QByteArray approach, you will get something similar to DBus. You serialize and deserialize your messages and automatically make sure that all message recipients receive their own copy of the messages with all the benefits that you get if you perform parallel computing.
source share