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. Not able to inline JS function when overriding
Forum Updated to NodeBB v4.3 + New Features

Not able to inline JS function when overriding

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 274 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.
  • M Offline
    M Offline
    mjohn
    wrote on last edited by
    #1

    I have a generic component that defines a generic function for MouseArea.onPressed events. When I create an instance of this component I want to override this function. It works if I define the function first and then override the generic function but it doesn't work if I try to do this inline.

    Example:
    My generic component

    import QtQuick 2.0
    
    Rectangle {
        property int posX
        property int posY
        property string imageSource
        property string entryText
    
        function onPress() {
            console.log("NavigationBarEntry Pressed: " + entryText)
        }
        property var entryOnPressed: (onPress)
    
        width: parent.width
        height: 56
        color: mBrandingDefsId.cThemeL1Bars
        x: posX
        y: posY
        Image {
            source: imageSource
            width: 35
            height: 35
            x: 8
            anchors.verticalCenter: parent.verticalCenter
        }
        Text {
            text: entryText
            x: 62
            font {
                family: boldFont.name
                pixelSize: 20
                bold: true
            }
            anchors.verticalCenter: parent.verticalCenter
        }
    
        MouseArea {
            anchors.fill: parent
            onPressed: onPress()
        }
    }
    

    When creating an instance of this, the following will work:

    NavigationBarEntry {
        entryText: "Home"
        function onPress() {
            console.log("Pressed Home")
        }
        entryOnPressed: (onPress)
    }
    

    But this will not:

    NavigationBarEntry {
        entryText: "Home"
        entryOnPressed: (function() {
            console.log("Pressed Home")
        })
    }
    

    It seems this should be possible. What I'm I missing?

    Thanks.

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      @mjohn said in Not able to inline JS function when overriding:

      MouseArea {
      anchors.fill: parent
      onPressed: onPress()
      }

      Your mouse area is calling onPress, not entryOnPressed.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      2

      • Login

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