abergmeier
abergmeier

Reputation: 14042

Pass a QVariantMap to Javascript (QtWebkit)

I have a QVariantMap, which I would like to pass to Javascript via a signal.

c++:

signals:
    void mysignal( QVariantMap map );


QVariantMap map;
map.insert( "id", 54 );
emit mysignal( map );

js:

mybinding.mysignal.connect( this, function( map ) {
    alert( "Map: " + map );  
} );

Now the alert just displays Map:. Could someone tell me what I am doing wrong?

Upvotes: 1

Views: 401

Answers (2)

Udenaka
Udenaka

Reputation: 21

mybinding.mysignal.connect( this, function( map ) {
    alert( "Map: " + map );  
} );

You map is a object (QVariantMap). so if you wan to access the values you should use

mybinding.mysignal.connect( this, function( map ) {
    alert( "Map_ID: " + map.id );  
} );

This give you an alert message indicating 54

Upvotes: 1

abergmeier
abergmeier

Reputation: 14042

Found that passing via QVariant works:

c++:

signals:
    void mysignal( QVariant map );



QVariantMap map;
map.insert( "id", 54 );
emit mysignal( QVariant::fromValue(map) );

Why the binding does work only this way? I have no idea.

Upvotes: 0

Related Questions