Call from function in QML?

I can easily use the element using InvokeActionItem on the page, but I need to be able to call it on the listview element. I managed to make a call, but I can’t figure out how to add data when it starts. I keep getting error message

InvocationPrivate :: setQuery: you are not allowed to modify the InvokeQuery object

Note. I am trying to do this in pure QML, I will do it with C ++ if necessary, but QML would be preferable.

Code that works inside the Page object:

actions: [ InvokeActionItem { ActionBar.placement: ActionBarPlacement.OnBar title: "Share" query { mimeType: "text/plain" invokeActionId: "bb.action.SHARE" } onTriggered: { //myTextProperty is a string variable property for the page. data = myTextProperty; } } ] 

The code I tried to use on another element looks like this, but DOES NOT work:

 Container { gestureHandlers: [ TapHandler { LongPressHandler { onLongPressed: { console.log("Longpress"); invokeQuery.setData("test"); invokeShare.trigger("bb.action.SHARE"); } } ] attachedObjects: [ Invocation { id: invokeShare query: InvokeQuery { id:invokeQuery mimeType: "text/plain" } } ] } 

Is there a way to change the data to be called only with QML, or do I just need to run it using C ++?

+4
source share
3 answers

After a lot of forums for viewing and testing various methods, I finally found one that works.

Add the following to your attached objects:

 attachedObjects: [ Invocation { id: invokeShare query: InvokeQuery { id:invokeQuery mimeType: "text/plain" } onArmed: { if (invokeQuery.data != "") { trigger("bb.action.SHARE"); } } } ] 

Then, where you need to call the call, follow these steps:

 invokeQuery.mimeType = "text/plain" invokeQuery.data = "mytext"; invokeQuery.updateQuery(); 

Please note: if you do not check onArmed for data, it will automatically call upon creation - in the case of a list, this can lead to 20 + screens asking to share on bbm ...;)

+11
source

In fact, you can use InvokeActionItem, you just need to call updateQuery to rerun invokeQuery. When ListItemData changes, the binding will update the values.

 InvokeActionItem { enabled: recordItem.ListItem.data.videoId != undefined id: invokeAction query{ uri: "http://www.youtube.com/watch?v=" + recordItem.ListItem.data.videoId onQueryChanged: { updateQuery() } } } 
+1
source

To remove "InvocationPrivate :: setQuery: you are not allowed to modify the InvokeQuery object" I use this:

 attachedObjects: [ Invocation { id: invoke query { mimeType: "text/plain" invokeTargetId: "sys.bbm.sharehandler" onDataChanged: { console.log("change data") } } onArmed: { if (invoke.query.data != "") { invoke.trigger("bb.action.SHARE"); } } } ] function shareBBM(){ invoke.query.setData("TEXT TO SHARE"); invoke.query.updateQuery(); } 
+1
source

All Articles