i have a few clients reading from the same data holder. what method would you recommend using to make sure they're all informed when data changes for an object not able to emit signals?
Printable View
i have a few clients reading from the same data holder. what method would you recommend using to make sure they're all informed when data changes for an object not able to emit signals?
Observer pattern, you can find a lot more on that subject.
would it be a good idea to use Qt's event system for that?
In theory yes, but it requires that the (receiving) object inherits QObject and then you can use signals and slots instead.
the sending element cant be a QObject, then this might be a good dir
Still you can use a has-a relationship with a QObject instead of an is-a relation. Just like QFuture and QFutureWatcher are related.
im not quite sure i know what you meant.. who has whom?
anyhow, say i post an event - who is the receiver? will it reach the rest of the gui if i send it to the main window?
You can look into Qt's source code but I suspect it's something like this:
Code:
class Watcher; class Object { private: QList<Watcher*> m_watchers; friend class Watcher; void notify(); }; Q_OBJECT public: signals: void objectChanged(Object*); friend class Object; }; void Object::notify() { foreach(Watcher *w, m_watchers) emit w->objectChanged(this); }
Every object that wanted to receive notifications.Quote:
anyhow, say i post an event - who is the receiver?
No, unless each interested object installs an event filter on the main window object.Quote:
will it reach the rest of the gui if i send it to the main window?