从QML中的功能调用? [英] Invocation from function in QML?

查看:180
本文介绍了从QML中的功能调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用Page中的InvokeActionItem轻松共享一个项目,但是我需要能够在listview项中调用它.我设法触发了调用,但是我无法弄清楚如何在触发时添加数据.我不断收到

I can share an item easily using an InvokeActionItem in a Page but I need to be able to call it in a listview item. I've managed to trigger an invoke, but I cannot figure out how to add data when triggering it. I keep getting an error message of

InvocationPrivate :: setQuery:不允许更改InvokeQuery对象

InvocationPrivate::setQuery: you are not allowed to change InvokeQuery object

注意:我试图在纯QML中执行此操作,如有必要,我会通过c ++进行操作,但是QML是更可取的.

Note: I am trying to do this in purely QML, I will do it via c++ if necessary but QML would be preferable.

在Page对象内工作的代码:

Code that works inside a 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've tried to use in the other item is as follows, 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"         
       }   
    }
]
}

是否有一种方法可以完全通过QML更改用于调用的数据,还是只需要通过c ++运行它?

Is there a way to change the data for an invoke purely with QML or do I need to just run it through c++ instead?

推荐答案

经过大量浏览论坛并测试了各种方法之后,我终于找到了一种可行的方法.

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

在您的AttachedObjects中添加以下内容:

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();

请注意,如果您不检查onArmed中的数据,它将在创建时自动调用调用-如果使用listview,则可能会导致20多个屏幕要求您在bbm上共享...;)

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... ;)

这篇关于从QML中的功能调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆