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. Continuously reading the change of a variable happens in one qml file in another qml file
Forum Updated to NodeBB v4.3 + New Features

Continuously reading the change of a variable happens in one qml file in another qml file

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
12 Posts 3 Posters 3.7k 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.
  • mamoudM Offline
    mamoudM Offline
    mamoud
    wrote on last edited by mamoud
    #3
    This post is deleted!
    1 Reply Last reply
    0
    • mamoudM Offline
      mamoudM Offline
      mamoud
      wrote on last edited by mamoud
      #4
      This post is deleted!
      1 Reply Last reply
      0
      • dheerendraD dheerendra

        I want to check this change from Curve.qml

        Your question and last statement confused me. What I understand is that you would like to 1. change the variable in Curve.qml.
        2. Check this change in Screen.qml
        3. Based on the value you would like to show the popup.

        Hope this is the correct problem statement.
        Now you are already creating the Curve object inside the Screen.qml. Check onModifiiedChange signal inside the curvepage in Screen.qml. Based on this you take the appropriate action.

        mamoudM Offline
        mamoudM Offline
        mamoud
        wrote on last edited by mamoud
        #5

        @dheerendra

        Hi, thank you for your reply. Yeah what I want is:

        1- When Up or Down buttons in Curve.qml is pressed, (modified) changes from false to true (that already happens correctly in Curve.qml)

        2- I want to check this change in Screen.qml, i mean to check that modifeid is changed to true.
        3- Based on this (modifeid is changed or not) i will take an action

        I tried this:

        I tried to add this part in curvepage in Screen.qml, but did not work as i want.

        Screen.qml

                id: curvepage
                modified: false
                onModifiedChanged:{ if(curvepage.modified ===false){
                                       curvepage.modified = true
                                   }
        

        and also i added to Curve.qml

        Curve.qml

            signal modifiedChanged
        
        

        But it seems i do something wrong

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by dheerendra
          #6

          ok. No need to add modifiedChanged signal. When you declare any property it will have signal defined already. In your case modified is the property added. So it will have signal called modifiedChanged in Curve.qml

          You should just call in Screen.qml

          Curve {
                   onModifiedChanged :{
                          console.log(modified)
                   }
          }
          

          This should work for you. Just check. If not I will give you sample program shortly.

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

          mamoudM 1 Reply Last reply
          0
          • dheerendraD dheerendra

            ok. No need to add modifiedChanged signal. When you declare any property it will have signal defined already. In your case modified is the property added. So it will have signal called modifiedChanged in Curve.qml

            You should just call in Screen.qml

            Curve {
                     onModifiedChanged :{
                            console.log(modified)
                     }
            }
            

            This should work for you. Just check. If not I will give you sample program shortly.

            mamoudM Offline
            mamoudM Offline
            mamoud
            wrote on last edited by mamoud
            #7

            @dheerendra

            Thanks again, but it did not work with me, I am not sure if this maybe a reason or not but in Screen.qml, the if condition is under onMainButtonPressed like this

            Screen.qml

            ScreenBase {
                id: root
            
                   onMainButtonPressed: {
            
                    if (button === "1"){ // a button when i press, what it does is either to show a popup warning that no changes in the curve have been done, or to activate a button without any warnings if changes happened to the curve.
            
                        if (functions.func1) { // this is just to check if the function is set or not 
                            if(curvepage.modified ===false){
                                showNotice = true // this shows a popup that no changes happened in the curve
            
                            } else if(curvepage.modified === true) {
                                functions.functionPressed; // a button is pressed and shown pressed on screen and no popup warnings are shown
                        }
            
                        }
                    }
            
            }
            
            
            will this cause a problem when i call (modified) from Curve object on the same Screen.qml?
            
            It looks like it only reads the modified value that i set initially, I mean if in  Curve object I do like this:
            
            
                id: curvepage
                modified: true
                onModifiedChanged :{
                        console.log(modified)
                 }
            

            }

            
            it will perform the other option when modifeid is true
            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by dheerendra
              #8

              Check the following sample. Based on this you should be able to make your changes.

              ======Screen.qml =====
              import QtQuick 2.11
              import QtQuick.Window 2.11
              
              Window {
                  visible: true
                  width: 640
                  height: 480
                  title: qsTr("Hello World")
                  MyCurve{
                      id : curve
                      onModifiedChanged: {
                          console.log(modified)
                      }
                  }
              }
              
              ============MyCurve.qml ==========
              
              import QtQuick 2.0
              import QtQuick.Controls 2.2
              
              Rectangle {
                  id : top
                  width: 400;height: 400;color: "blue"
                  property bool modified : false
                  Row {
                      Button{
                          text :"True"
                          onClicked: {
                             top.modified=true;
                          }
                      }
                      Button{
                          text :"False"
                          onClicked: {
                             top.modified=false;
                          }
                      }
                  }
              }
              

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

              1 Reply Last reply
              0
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on last edited by
                #9

                @mamoud is the issue resolved ? Do you need help ?

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

                mamoudM 1 Reply Last reply
                0
                • dheerendraD dheerendra

                  @mamoud is the issue resolved ? Do you need help ?

                  mamoudM Offline
                  mamoudM Offline
                  mamoud
                  wrote on last edited by mamoud
                  #10

                  @dheerendra

                  Hi, thank you for this, but I still have the problem. modified state is not changed in Screen.qml file.

                  Here I can show you more detailed code, maybe i have another problem that cause this.

                  In Curve.qml

                  Rectangle {
                      id: curvepage
                  
                      width: 320
                      height: 240
                      property bool modified: false // initially no changes happened in the curve
                      // I want to check when modified is turned to true and read this change in Screen.qml 
                  
                  
                           if (button === "up" || button === "down"  )
                          {
                              curvepage.modified = true;
                          }
                  

                  I guess no prolem here. But in Screen.qml, I have this:

                  Screen.qml

                  ScreenBase { // object from anothe qml file called **ScreenBase.qml**
                      id: root
                  
                         onMainButtonPressed: {// from ScreenBase.qml file
                  
                          if (button === "1"){ // a button when i press, what it does is either to show a popup warning that no changes in the curve have been done, or to activate a button without any warnings if changes happened to the curve.
                  
                              if (functions.func1) { // this is just to check if the function is set or not 
                                  if(curvepage.modified ===false){
                                      showNotice = true // this shows a popup that no changes happened in the curve
                  
                                  } else if(curvepage.modified === true) {
                                      functions.functionPressed; // a button is pressed and shown pressed on screen and no popup warnings are shown
                              }
                  
                              }
                          }
                  
                  Curve{ // object is called inside **ScreenBase object** which is written in **Screen.qml file**
                  
                          id: curvepage
                          modified: true
                          onModifiedChanged :{
                                  console.log(modified)
                           }
                  }
                  
                  }
                  

                  Does this make any problem while calling the variable (modified) from Curve.qml to Screen.qml. should i add anything in ScreenBase.qml??

                  The ScreenBase.qml file is a rectangle like this:

                  ScreenBase.qml

                  Rectangle {
                      id: root
                      width: 320
                      height: 240
                      clip: true 
                  // and some other buttons definitions
                  

                  Also to clarify, When i press a butto to change a value on the curve, no matter if i increase or decrease, I just want to check if there is any change, so if i did not press any button, (modified) will be false, if i press any button (modified) will be true

                  Thank you very much for your help, but i am abit confused while dealing with those different files

                  T 1 Reply Last reply
                  0
                  • mamoudM mamoud

                    @dheerendra

                    Hi, thank you for this, but I still have the problem. modified state is not changed in Screen.qml file.

                    Here I can show you more detailed code, maybe i have another problem that cause this.

                    In Curve.qml

                    Rectangle {
                        id: curvepage
                    
                        width: 320
                        height: 240
                        property bool modified: false // initially no changes happened in the curve
                        // I want to check when modified is turned to true and read this change in Screen.qml 
                    
                    
                             if (button === "up" || button === "down"  )
                            {
                                curvepage.modified = true;
                            }
                    

                    I guess no prolem here. But in Screen.qml, I have this:

                    Screen.qml

                    ScreenBase { // object from anothe qml file called **ScreenBase.qml**
                        id: root
                    
                           onMainButtonPressed: {// from ScreenBase.qml file
                    
                            if (button === "1"){ // a button when i press, what it does is either to show a popup warning that no changes in the curve have been done, or to activate a button without any warnings if changes happened to the curve.
                    
                                if (functions.func1) { // this is just to check if the function is set or not 
                                    if(curvepage.modified ===false){
                                        showNotice = true // this shows a popup that no changes happened in the curve
                    
                                    } else if(curvepage.modified === true) {
                                        functions.functionPressed; // a button is pressed and shown pressed on screen and no popup warnings are shown
                                }
                    
                                }
                            }
                    
                    Curve{ // object is called inside **ScreenBase object** which is written in **Screen.qml file**
                    
                            id: curvepage
                            modified: true
                            onModifiedChanged :{
                                    console.log(modified)
                             }
                    }
                    
                    }
                    

                    Does this make any problem while calling the variable (modified) from Curve.qml to Screen.qml. should i add anything in ScreenBase.qml??

                    The ScreenBase.qml file is a rectangle like this:

                    ScreenBase.qml

                    Rectangle {
                        id: root
                        width: 320
                        height: 240
                        clip: true 
                    // and some other buttons definitions
                    

                    Also to clarify, When i press a butto to change a value on the curve, no matter if i increase or decrease, I just want to check if there is any change, so if i did not press any button, (modified) will be false, if i press any button (modified) will be true

                    Thank you very much for your help, but i am abit confused while dealing with those different files

                    T Offline
                    T Offline
                    Tom_H
                    wrote on last edited by
                    #11

                    @mamoud You have incorrectly initialized curvepage.modified to true in Screen.qml.

                    mamoudM 1 Reply Last reply
                    0
                    • T Tom_H

                      @mamoud You have incorrectly initialized curvepage.modified to true in Screen.qml.

                      mamoudM Offline
                      mamoudM Offline
                      mamoud
                      wrote on last edited by
                      #12

                      @Tom_H
                      Hi thank you for reply,
                      but i have tried to delete it completely without any initalization in Curve object in Screen.qml, but still does not work

                      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