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. Passing variables between QML files
Forum Updated to NodeBB v4.3 + New Features

Passing variables between QML files

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 802 Views 2 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.
  • G Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    Hi,
    I have a getName text field in AddToDb.qml:

     property alias nameParameter: getName.text
    
        AppTextField {
            id: getName
            width: backgrnd.width / 2.4
    
            height: dp(35)
            placeholderText: "Enter the Friend's name."
            placeholderColor: ST.placeHColor()
            showClearButton: true
            radius: 30
    
            //        textColor: ST.textColor()
            cursorColor: ST.cursorClr()
            font.pixelSize: 15
            anchors.top: id.bottom
            anchors.topMargin: 15
            anchors.left: id.left
            backgroundColor: ST.editBackground()
    
            selectionColor: ST.selectionColor()
            borderColor: ST.borderClr()
            borderWidth: 1
    
            onEditingFinished: {
                if (getName.text.length < 2) {
                    var popup = EP.createMsg(backgrnd, {
                                                 "text": "The Friend's name must be at least 2 characters long."
                                             })
                }
            }
        }
    

    I want to read the value of getName in AddToDBPage2.qml like this:

    var myName = AddToDB.nameParameter
    console.log("AddToDb myName: ", myName)
    

    I keep getting undefined in the console log instead of the name. What am I missing? Thank you for your help.

    1 Reply Last reply
    0
    • rrlopezR Offline
      rrlopezR Offline
      rrlopez
      wrote on last edited by
      #2

      Hello @gabor53, is this AddToDBPage2.qml QML file parent of AddToDb.qml, is it sibling or are they totally unrelated? If they are parent/child or siblings then it should be easy to access via objectName.nameParameter. If they are unrelated, you will have to create some sort of variable accessible for both layouts and populate it from there.

      Lic-Ing. Rodrigo Lopez Gonzalez
      Embedded Software Engineer
      RidgeRun Engineering Ltd.
      www.ridgerun.com
      Email: rodrigo.lopez@ridgerun.com

      G 1 Reply Last reply
      0
      • rrlopezR rrlopez

        Hello @gabor53, is this AddToDBPage2.qml QML file parent of AddToDb.qml, is it sibling or are they totally unrelated? If they are parent/child or siblings then it should be easy to access via objectName.nameParameter. If they are unrelated, you will have to create some sort of variable accessible for both layouts and populate it from there.

        G Offline
        G Offline
        gabor53
        wrote on last edited by
        #3

        @rrlopez
        They are unrelated.

        1 Reply Last reply
        0
        • rrlopezR Offline
          rrlopezR Offline
          rrlopez
          wrote on last edited by
          #4

          @gabor53 you should be ok using QQmlContext: https://doc.qt.io/qt-5/qqmlcontext.html

          Lic-Ing. Rodrigo Lopez Gonzalez
          Embedded Software Engineer
          RidgeRun Engineering Ltd.
          www.ridgerun.com
          Email: rodrigo.lopez@ridgerun.com

          G 1 Reply Last reply
          0
          • rrlopezR rrlopez

            @gabor53 you should be ok using QQmlContext: https://doc.qt.io/qt-5/qqmlcontext.html

            G Offline
            G Offline
            gabor53
            wrote on last edited by
            #5

            @rrlopez
            I made some changes to the structure of the project. Both AddToDb.qml and AddToDBPage2.qml They are siblings and the parent is and other qml file called AddToDbMain.qml. In AddToDBPage2.qml when I typing

            var myName = AddToDB.nameParameter
            

            I can see the nameParameter property (after typing AddToDb. it pops up on the list), but the value is still undefined. What am I missing here?
            Thank you for your help.

            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