Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to access property alias
Forum Updated to NodeBB v4.3 + New Features

How to access property alias

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 448 Views
  • 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.
  • C Offline
    C Offline
    Circuits
    wrote on last edited by Circuits
    #1

    There is a variable declared in this QML file and I was wondering if I will have access to it from another QML file? The variable is declared as property alias:

    property alias displayValue: currentValue.text
    

    is it possible to access this variable from any other QML file? I tried saying:

     property string inputValue: InputField.currentValue.text
    

    InputField turns green when I call it like this so I think it's recognizing the correct QML file but it's not working:

    TypeError: Cannot read property 'text' of undefined
    
    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Access it like follows.

      InputField.displayValue

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      C 1 Reply Last reply
      0
      • dheerendraD dheerendra

        Access it like follows.

        InputField.displayValue

        C Offline
        C Offline
        Circuits
        wrote on last edited by
        #3

        @dheerendra For some reason it is telling me the value is undefined:

        Unable to assign [undefined] to QString
        
        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          What is InputField ?

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          C 1 Reply Last reply
          0
          • dheerendraD dheerendra

            What is InputField ?

            C Offline
            C Offline
            Circuits
            wrote on last edited by Circuits
            #5

            @dheerendra InputField is the name of the QML file which creates the instance of this keyboard. It is also the id of this AbstractInputField within the script:

            id: inputField
                property alias displayValue: currentValue.text
                property alias placeholderText: currentValue.placeholderText
                property alias validator: editingValue.validator
                property int horizontalAlignment: TextInput.AlignLeft
                property bool doSelection: true
                readonly property alias isEditing: editingValue.visible
            
                signal accepted(string value)
                height: style.height
            
                implicitWidth: editingValue.implicitWidth
                implicitHeight: editingValue.implicitHeight
            
                QQC2.TextField {
                    id: currentValue
                    anchors.fill: parent
                    background: Rectangle{
                        anchors.fill: parent
                        radius: inputField.style.radius
                        border.width: inputField.style.fieldOutlineSize
                        border.color: inputField.style.fieldOutlineColor
                    }
            
                    readOnly: true
                    horizontalAlignment: inputField.horizontalAlignment
                    visible: !(editingValue.activeFocus)
                    font: inputField.style.font.font
                    color: inputField.readOnly ? inputField.style.readOnlyFontColor : inputField.style.inputFontColor
            
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            if (!inputField.readOnly)
                                editingValue.forceActiveFocus()
                        }
                    }
                }
            
                QQC2.TextField {
                    id: editingValue
                    focus: true
                    height: inputField.style.height
                    visible: activeFocus
                    horizontalAlignment: inputField.horizontalAlignment
                    onAccepted: {
                        inputField.accepted(text)
                        keyboardPanel.target = null
                        currentValue.forceActiveFocus()
                    }
            
                    onActiveFocusChanged: {
                        if (activeFocus) {
                            text = currentValue.text
                            if (doSelection)
                                selectAll()
                            keyboardPanel.target = ( presentationManager.guiSettingsPresenter.model.virtualKeyboardEnabled
                                                     ? inputField
                                                     : null )
                        } else {
                            inputField.accepted(text)
                            keyboardPanel.target = null
                        }
                    }
                }
            
                function cancel() {
                    keyboardPanel.target = null
                    currentValue.forceActiveFocus()
                }
            }
            
            

            I really just need access to the displayValue outside of InputField. Perhaps I could do that with signals?

            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