Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved] edit function
Forum Updated to NodeBB v4.3 + New Features

[solved] edit function

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nhojyer07
    wrote on last edited by
    #1

    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...
    }@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      aalpert
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nhojyer07
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • R Offline
          R Offline
          roopeshchander
          wrote on last edited by
          #4

          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)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved