Invocation from function in QML?

流过昼夜 提交于 2019-12-04 12:50:35

After a fair amount of browsing forums and testing various methods, I have finally found one that works.

Add the following in your attachedObjects:

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

Then wherever you need to call the invocation do the following:

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

Note that if you do not do a check in the onArmed for data it will automatically call the invocation on creation - in the case of a listview this can result in 20+ screens asking you to share on bbm... ;)

You can actually use the InvokeActionItem, you just have to call updateQuery to retrigger the invokeQuery. When the ListItemData changes, the binding will cause the values to update.

InvokeActionItem {
      enabled: recordItem.ListItem.data.videoId != undefined

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

}

For remove "InvocationPrivate::setQuery: you are not allowed to change InvokeQuery object" message 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();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!