[Qt-qml] Using C++ classes in signals on the QML side
Ademar de Souza Reis Jr.
ademar.reis at openbossa.org
Fri Mar 26 22:48:38 CET 2010
Hi there.
Is there a way to use an exported C++ class as a parameter in a
signal sent to QML?
Following the code from examples/declarative/extending/signal/, this is what I wan to do:
["Boy" is a C++ class exported to QML]
birthdayparty.h:
signals:
void partyStarted(const QTime &time);
+ void newGuestString(const QString &str); // works
+ void newGuestBoy(const Boy &guest); // doesn't
example.qml:
BirthdayParty {
onPartyStarted: console.log("This party started rockin' at " + time);
+ onNewGuestBoy: console.log("There's a new guest (boy): " + guest.name); // doesn't work
+ onNewGuestString: console.log("There's a new guest (string): " + str); // works
(simplified diff, you get the idea)
This is the output when the three signals are emitted from the C++ code:
"""
This party started rockin' at 18:16:16
QMetaProperty::read: Unable to handle unregistered datatype 'Person' for property 'QDeclarativeBoundSignalParameters::guest'
file::example.qml:7: TypeError: Result of expression 'guest' [undefined] is not an object.
There's a new guest (string): foobar
"""
So as you can see using QTime and QString works, but using Boy doesn't. Any ideas?
Thanks,
- Ademar
--
Ademar de Souza Reis Jr. <ademar.reis at openbossa.org>
OpenBossa Labs - Instituto Nokia de Tecnologia (INdT)
http://www.openbossa.org/
http://www.indt.org.br/
^[:wq!
More information about the Qt-qml
mailing list