Alexandre Hitchcox
Alexandre Hitchcox

Reputation: 2753

Call function to a non parent object

Lets say I have a QML that contains this:

MainView {
    id: main
    Component {
        MyItem {
            // has function doSomething()
            id: item
            function doSomething() // this will work
            Child {
                function parent.doSomething() // this too
                function item.doSomething() // and this
            }
        }
    }
    Page {
        // here is where I would like to be able to call the function
    }
}

I'm unable to call the function doSomething() from anything that's not a child, is it possible to call it for example from inside the Page {} object?

I'm sorry for the question being so badly written, but I'm unsure of how to put it in another way. Thanks for your time.

Upvotes: 2

Views: 759

Answers (1)

TheBootroo
TheBootroo

Reputation: 7518

That's because you wrapped into a Component item, which acts like a separated file sandboxing the var/function scope. So from inside the component you can access the outside but the opposite is impossible. The only trick to acheive what you're trying to do would be to declare a signal in an outside element, add a Connections item inside your component and fire you signal when you need to trigger the inner function.

Upvotes: 3

Related Questions