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:)]Value from one qml file to another qml file
Forum Updated to NodeBB v4.3 + New Features

[Solved:)]Value from one qml file to another qml file

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 4.0k 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.
  • R Offline
    R Offline
    ReshmaS
    wrote on last edited by
    #1

    I have a SLider.qml - its like a bar wit which we can slide from min value to max value say from 10 to 100 respectively.
    I include this Slider.qml file in my main file as Slider { specify its parameters;like width, height, min value, max value}. Now I have a textedit field in my main.qml which should take the value of tat slider. I tried different methods like writing a common js file and getting the values but failed. I would appreciate if you could help me out of this. I am unable to proceed further. Thanks for your time.

    God Bless..

    Reshma

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

      Which god would that be?

      More seriously: saying "I have tried different methods" does not tell us much, and you should not expect people to guess what you have done. You need to list what you have done, provide some code for us to work on. Google for "smart questions" to get a better idea.

      PLease specify what you mean by "Now I have a textedit field in my main.qml which should take the value of tat slider". You need this property to be set declaratively or imperatively? There are a dozen ways in which your problem can be fixed, I need to see how you declare things in order to give you the answer that will work for you.

      (Z(:^

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ReshmaS
        wrote on last edited by
        #3

        @import QtQuick 1.1

        Item{
        id:slider_value

        property alias minValue_slider :min.text
        property alias maxValue_slider :max.text
        property int g:((maxValue_slider*1)-(minValue_slider*1))
        width:250
        height:50
        
        
        
        Rectangle {
            id: rectangle1
            x: 32
            y: 15
            width: g+20
            height: 10
            color: "black"
            radius:5
            smooth:true
        
        
            Rectangle {
                id: rectangle2
                width: 20
                height: 10
                radius:25
                color: "red"
                smooth:true
        
                MouseArea {
        
                    anchors.fill:parent
                    drag.target: rectangle2
                    drag.axis: Drag.XAxis
                    drag.minimumX:0
                    drag.maximumX: g
                    onPositionChanged:  {text_input1.text=max.text-rectangle2.x
        
                    }
        
                }
            }
        
        }
        
        
        
        TextEdit {
            id: text_edit1
            x: 60
            y: 43
            width: 80
            height: 20
            font.pixelSize: 12
            TextInput {
                id: text_input1
                x: 11
                y: 0
                width: 80
                height: 20
                text:max.text
                selectedTextColor: "#cf7171"
                font.pixelSize: 12
            }
        }
        
        Text {
            id: max
            x: 32
            y: 37
            text: "210"
            font.bold:true
        }
        
        Text {
            id: min
            x: 180
            y: 37
            text: "40"
            font.bold:true
        }
        

        }

        @

        Sliding.qml

        Reshma

        1 Reply Last reply
        0
        • R Offline
          R Offline
          ReshmaS
          wrote on last edited by
          #4

          main.qml

          @import QtQuick 1.1

          Rectangle {
          width: 250
          height: 250

          color:"lightsteelblue"
          
          
          
          
          // I Want the value of Slider in value.text
          SlidingValue{
          
              minValue_slider: "10"
              maxValue_slider: "100"
          
          }
          
          //
          
          TextInput {
              id: value
              x: 97
              y: 70
              width: 80
              height: 20
              text: qsTr("text")
              font.pixelSize: 12
          }
          

          }
          @

          So, I want the value of the slider to be displayed in value.text field.

          Sorry I am quite new to qml/qt my questions may be little dumb. Am just a beginner.

          Reshma

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

            No need to be sorry about being a beginner, every one of us here has been one at some point in time, and there surely is a lot that we still don't know. The fact I was hinting at is to be mindful about the fact that a) you need help, b) we want to help you, c) it's good to make our lives easier by asking those so-called smart questions. I am not angry, I just pointed out where your post was lacking :)

            The crucial part of text_input1 is missing, so I can't be absolutely sure, but so far it looks like this: in order for a property of any QML file to be visible "outside" (that is, when you include it from another file), you have to declare it in the topmost component of that file. So, in your case it would be something like this:
            @
            // Sliding.qml
            Item {
            property int sliderValue: 0 // or any other value/ binding
            }

            // main.qml
            Sliding {
            id: slider
            }

            // This is where you want to display:
            Text {
            text: slider.sliderValue
            }
            @

            Just a quick sketch, but should give you the idea. If it's still not clear, ask for more :D

            (Z(:^

            1 Reply Last reply
            0
            • R Offline
              R Offline
              ReshmaS
              wrote on last edited by
              #6

              Perfect!! Thanks a ton Sierdzio. I will try to be a smarter with my questions. Thanks for your advice, I will keep it in mind next time :)

              Reshma

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

                Pleasure :) If the issue is solved for you, please prepend "[Solved]" to subject's topic.

                (Z(:^

                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