[Qt-qml] Using C++ classes in signals on the QML side
aaron.kennedy at nokia.com
aaron.kennedy at nokia.com
Mon Mar 29 02:11:02 CEST 2010
Hi,
On 27/03/10 7:48 AM, "ext Ademar de Souza Reis Jr."
<ademar.reis at openbossa.org> wrote:
> 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?
Assuming Boy is a C++ class exposed to QML as you say, emitting it as a
pointer parameter should work. For example
signals:
void newGuestBoy(const Boy *guest)
Cheers,
Aaron
More information about the Qt-qml
mailing list