[solved] edit function



  • So I have here another problem that I can't solve. Hope you can help me with this.

    Let's say we have a QML file named "Xxx":

    @import QtQuick 1.0

    Item {
    function foo() {
    ...some code...
    }
    }@

    And another QML file:

    @Item {
    Xxx {
    function foo() {
    ...another code...
    }
    }@

    How do I combine both codes in function foo without rewriting the first one like this:

    @function foo() {
    ...some code...
    ...another code...
    }@



  • If you didn't give them the same name, you could call one function from within the other, e.g.

    Item{ Xxx { function bar() { foo(); otherCode(); } }

    If you give them the same name, you hide the method on type Xxx and can't invoke it.



  • I see. I'll just nest the functions then. Thanks!



  • If you really like the name 'foo' you could also do:

    Yyy.qml:
    @
    Item {
    Xxx {
    id: xxxItem
    }
    function foo() {
    xxxItem.foo();
    ...another code...
    }
    }
    @

    (but that would expose Yyy.foo() if Yyy is used as an item)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.