[Qt-interest] [Properties] The NOTIFY signal, and the READ and WRITE functions
Thiago Macieira
thiago at kde.org
Thu Jan 28 20:16:39 CET 2010
Em Quinta-feira 28 Janeiro 2010, às 15:23:33, Louis Du Verdier escreveu:
> Hello,
>
> In a project, I have to use properties with the NOTIFY signal. So I have
> declared the following property : Q_PROPERTY(bool myProperty READ getValue
> WRITE setValue NOTIFY valueChanged); In my opinion, the READ and WRITE
> functions, like the NOTIFY signal, should not be managed by me, but I
> don't manage them, my compilator say that my code have mistakes. It don't
> say anything if I write my WRITE function like it :
> void MyWidget::setValue(bool v)
> {
> value = QVariant(v);
> emit valueChanged(v);
> }
> But if we have to manage the acessor/... functions, what is the utility of
> properties ? So I think my code is wrong, and that I have forgoten
> something.
Declaring the Q_PROPERTY means moc will extract the information about your
property and add to the meta object.
That means you can do run-time reflection into the objects and find out what
they have available. Take a look at the QMetaObject and QMetaProperty classes.
This run-time reflection mechanism is used by a couple other Qt technologies.
It's used by both QtScript and QtDBus to determine what from your object can
be exported to the script/D-Bus environment.
It's also used by the upcoming QtDeclarative module to determine what is
exported from your class into the QML world.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100128/0744f320/attachment.bin
More information about the Qt-interest-old
mailing list