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 (work-around)] QML Calling overriden functions
Forum Updated to NodeBB v4.3 + New Features

[SOLVED (work-around)] QML Calling overriden functions

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 10.1k 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.
  • P Offline
    P Offline
    PGPoulsen
    wrote on last edited by
    #1

    Hi, I'm playing with inheritance in QML and don't know how to call an overridden function. Below is a simple example that, hopefully, explains what I'm trying to do.

    Thanks in advance.
    Yours
    /peter

    Parent.qml: @

    import QtQuick 1.1

    Rectangle {
    function foo() {
    console.log("Foo in parent")
    }
    }@

    Child.qml:
    @
    import QtQuick 1.1

    Parent {
    function foo() {
    console.log("Foo in child")
    // here is the problem. Would like to do something like: Parent::foo()
    }
    }@

    Output:
    @
    Foo in child
    @

    While I would like it to be:
    @
    Foo in child
    Foo in parent
    @

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      No time to check myself at the moment, but have you tried this:
      @
      import QtQuick 1.1

      Parent {
      id: root

      function foo() {
          root.foo();
          console.log("Foo in child")
      }
      

      }
      @

      Probably won't work, or will introduce some nasty loop, but worth a try nonetheless.

      (Z(:^

      1 Reply Last reply
      0
      • P Offline
        P Offline
        PGPoulsen
        wrote on last edited by
        #3

        Thanks for you answer, but unfortunately it does go into a nasty loop :-(

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          A kind of a workaround, if you are interested in those, would be this:
          @
          // Parent
          import QtQuick 1.1

          Rectangle {

          signal foo();
          onFoo: {
              console.log("Foo in parent");
          }
          

          }

          // Kid
          import QtQuick 1.1

          Parent {
          id: root

          onFoo: {
              console.log("Foo in child");
          }
          

          }
          @

          This time I've checked - it works :)

          (Z(:^

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            Although in a reversed order to the one you were interested in. Parent reports first.

            (Z(:^

            1 Reply Last reply
            0
            • C Offline
              C Offline
              chriadam
              wrote on last edited by
              #6

              https://bugreports.qt-project.org/browse/QTBUG-25942 and https://bugreports.qt-project.org/browse/QTBUG-26357 are related to this issue. Both of these are in scope for Qt 5.1.

              Cheers,
              Chris.

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #7

                Good to know, thanks!

                (Z(:^

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  PGPoulsen
                  wrote on last edited by
                  #8

                  Thanks for all your answers. Very helpful :-)

                  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