[Qt-interest] Get notification of QObject property changes?
Rohan McGovern
rohan.mcgovern at nokia.com
Fri Jul 31 00:21:27 CEST 2009
On Friday 31 July 2009, ext André Somers wrote:
> Hi,
Hi,
>
> I was wondering if it is possible to get some kind of
> notification from the Qt (meta) object system that properties on
> a monitored QObject have changed? While digging in the
> documentation, I stumbled on QMetaProperty::notifySignal and the
> NOTIFY keyword for the Q_PROPERTY macro that allows you to define
> a signal to be emitted at property change, but it seems I will
> have to define this in advance. I really would like to somehow
> monitor QObjects without specifically instrumenting these objects
> in advance at design time. Is there a way I can set the signal
> afterwards, perhaps through Qt’s introspection methods? Is there
> perhaps some general signal that I can have a QObject emit on any
> property change, or some other hook I can use?
I don't believe so.
Q_PROPERTY is just annotation on top of existing C++ functions. It
doesn't intercept the calls to those functions, so properties can
be modified without going through any part of the metaobject system
(just as slots can be called as you would call any old C++
function).
You have to put your own hook in (as a signal) and make sure it's
activated at the appropriate time. NOTIFY is the mechanism for you
to advertise that hook.
NOTIFY was added so script engines (mostly declarative UI) can take
some action when a property's value is changed. At some point I
believe the declarative UI engine would simply poll the value of a
property if there was no NOTIFY signal, which technically works and
may work for you but it's a bad solution.
--
Rohan McGovern
Qt Software QA, Nokia
More information about the Qt-interest-old
mailing list