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. Dialog QML open passing variable
Forum Updated to NodeBB v4.3 + New Features

Dialog QML open passing variable

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 4 Posters 938 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.
  • M Offline
    M Offline
    marco_88
    wrote on last edited by
    #1

    Hi. I made a dialog about QML that works, but I have some small problems. It must be outside the listView, but I must show text from the ListView model in the Dialog. In the onClicked of the MouseArea from which I open the dialog if I write this text in console.log that I want to display, I display it, so how can I pass this information to the dialog that I want to open to display it in there?
    Thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      D_Tec
      wrote on last edited by
      #2

      Hi Marco,

      I am a beginner but from what I found it is not possible to pass on a variable. What I did in your case is to use a "global" variable. With the button click I write the index of the clicked element to a variable that is accessible to the dialog. In the dialog I read in the element on the visible changed.

      ListView {
        id: dataView
        property int activeIndex: 0
      
        delegate: Rectangle {
          [...]
          Button {
             onClicked: activeIndex = index    
          }
        }
      }
      
      Dialog {
        onVisibleChanged: {
           var element = dataView.model.get(dataView.activeIndex)
        }
      }
      

      Hope that still helps =)

      B ODБOïO 2 Replies Last reply
      1
      • D D_Tec

        Hi Marco,

        I am a beginner but from what I found it is not possible to pass on a variable. What I did in your case is to use a "global" variable. With the button click I write the index of the clicked element to a variable that is accessible to the dialog. In the dialog I read in the element on the visible changed.

        ListView {
          id: dataView
          property int activeIndex: 0
        
          delegate: Rectangle {
            [...]
            Button {
               onClicked: activeIndex = index    
            }
          }
        }
        
        Dialog {
          onVisibleChanged: {
             var element = dataView.model.get(dataView.activeIndex)
          }
        }
        

        Hope that still helps =)

        B Offline
        B Offline
        Bob64
        wrote on last edited by
        #3

        @D_Tec Couldn't you introduce a property in the Dialog and assign the required value to it before you open the dialog?

        D 1 Reply Last reply
        2
        • D D_Tec

          Hi Marco,

          I am a beginner but from what I found it is not possible to pass on a variable. What I did in your case is to use a "global" variable. With the button click I write the index of the clicked element to a variable that is accessible to the dialog. In the dialog I read in the element on the visible changed.

          ListView {
            id: dataView
            property int activeIndex: 0
          
            delegate: Rectangle {
              [...]
              Button {
                 onClicked: activeIndex = index    
              }
            }
          }
          
          Dialog {
            onVisibleChanged: {
               var element = dataView.model.get(dataView.activeIndex)
            }
          }
          

          Hope that still helps =)

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          hi,

          @D_Tec said in Dialog QML open passing variable:

          var element = dataView.model.get(dataView.activeIndex)

          this will probably not work, activeIndex is just a property of the listview, it is not part of the model
          you should access it using the list id

           var element = dataView.activeIndex
          

          you can access to the model directly using get() method

              Component.onCompleted: {dataView.model.insert(0, {"age" : 100})}
              ListView {
                  id: dataView
                  model: ListModel{}
              }
            // dataView.model.get(0).age
          
          
          1 Reply Last reply
          0
          • B Bob64

            @D_Tec Couldn't you introduce a property in the Dialog and assign the required value to it before you open the dialog?

            D Offline
            D Offline
            D_Tec
            wrote on last edited by
            #5

            This code works for me. My dialogs contain the information from the model that I want when they are opened. I do not see where the difference is to @LeLev. Where you put your information on which item the user clicked does not matter.

            @Bob64 I do not know how access your dialogs but I guess you can assign a property and access it with dialogId.propertyName.

            B 1 Reply Last reply
            0
            • D D_Tec

              This code works for me. My dialogs contain the information from the model that I want when they are opened. I do not see where the difference is to @LeLev. Where you put your information on which item the user clicked does not matter.

              @Bob64 I do not know how access your dialogs but I guess you can assign a property and access it with dialogId.propertyName.

              B Offline
              B Offline
              Bob64
              wrote on last edited by
              #6

              @D_Tec "I guess you can assign a property and access it with dialogId.propertyName"

              Yes, exactly.

              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