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. How do I share object between pages of a SwipeView?

How do I share object between pages of a SwipeView?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
swipeviewscope
6 Posts 3 Posters 3.1k 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.
  • Steve FallowsS Offline
    Steve FallowsS Offline
    Steve Fallows
    wrote on last edited by
    #1

    I am having trouble understanding scope/name resolution in QML. I had the following code in a page of a SwipeView:

    import CTX 1.0
    import QtQuick 2.7
    import QtQuick.Dialogs 1.2
    import Qt.labs.settings 1.0
    
    CalibrationPageForm {
        id: page
        CTPanel {
            id: ct_panel
            Component.onCompleted: {
                ct_panel.setUp()  // Complete set up of the C++ object
                console.log("CT Panel component completed.")
            }
            receptorPath: receptorPath_textField.text
        }
        receptorPath_textField.text: settings.receptorPath
    < more code accessing the ct_panel object>
    } 
    

    CTPanel is defined in C++ in the CTX module. This worked, but now I need to access the CTPanel object from another page of the SwipeView. So I moved the CTPanel object up to the ApplicationWindow:

    import CTX 1.0
    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.0
    
    ApplicationWindow {
        visible: true
        width: 800
        height: 600
        title: qsTr("Application")
        id: app_window
    
        //property alias ct_panel: ct_panel
        
        SwipeView {
            id: swipeView
            anchors.fill: parent
            currentIndex: tabBar.currentIndex
    
            CalibrationPage {
            }
    
            AcquisitionPage {
            }
    
            PatientPage {
            }
    
            UtilsPage {
            }
        }
    
        CTPanel {
            id: ct_panel
            Component.onCompleted: {
                ct_panel.setUp()  // Complete set up of the C++ object
                console.log("CT Panel component completed.")
            }
        }
    < page indicator for SwipeView etc. >
    }
    

    Then tried to access it from the calibration page like this:

    CalibrationPageForm {
        id: page
        parent.ct_panel.receptorPath: receptorPath_textField.text
        
        receptorPath_textField.text: settings.receptorPath
    <remainder unchanged>
    }
    

    The id 'ct_panel' is not recognized in the CalibrationPageForm, no matter what I try. I've tried many variations of parent levels, id's and defining the property seen above in the ApplicationWindow, putting the CTPanel in the SwipeView etc.

    How do I define the CTPAnel object so I can access it from both the CalibrationPage and the AcquisitionPage? And how do I refer to it in those pages?

    Possibly my problem here is that I don't quite get the relationship of the Page and PageForm objects (Created by QtDesigner).

    1 Reply Last reply
    0
    • P Offline
      P Offline
      peteritv
      wrote on last edited by
      #2

      @Steve-Fallows
      Have you tried to put BOTH the property alias AND the CTPanel{} inside the SwipeView{}?

      1 Reply Last reply
      0
      • Steve FallowsS Offline
        Steve FallowsS Offline
        Steve Fallows
        wrote on last edited by
        #3

        I had not tried that, so I just did. I still get 'Cannot assign to non-existent property "ct_panel"' whether it use just 'ct_panel', 'parent.ct_panel' or 'swipeView.ct_panel' in CalibrationPageForm.

        Julien BJ 1 Reply Last reply
        0
        • Steve FallowsS Steve Fallows

          I had not tried that, so I just did. I still get 'Cannot assign to non-existent property "ct_panel"' whether it use just 'ct_panel', 'parent.ct_panel' or 'swipeView.ct_panel' in CalibrationPageForm.

          Julien BJ Offline
          Julien BJ Offline
          Julien B
          wrote on last edited by Julien B
          #4

          Hello @Steve-Fallows,

          You can access the data of another Item by its id, nevertheless you cannot access property from another item the way you did. I think you need to use JavaScript via signal handler.

          for example (assuming receptorPath_textField is also an id):

          onClicked: {
              ct_panel.receptorPath = receptorPath_textField.text;
          }
          

          What is the behaviour you are looking for? On which event do you want to change properties from ct_panel?

          Steve FallowsS 1 Reply Last reply
          0
          • Julien BJ Julien B

            Hello @Steve-Fallows,

            You can access the data of another Item by its id, nevertheless you cannot access property from another item the way you did. I think you need to use JavaScript via signal handler.

            for example (assuming receptorPath_textField is also an id):

            onClicked: {
                ct_panel.receptorPath = receptorPath_textField.text;
            }
            

            What is the behaviour you are looking for? On which event do you want to change properties from ct_panel?

            Steve FallowsS Offline
            Steve FallowsS Offline
            Steve Fallows
            wrote on last edited by
            #5

            @Julien-B I'm just trying to get the same behavior with the ct_panel object up one level from where it was. I want to bind the receptorPath property to the text field on the CalibrationPage. I'd prefer not to deal explicitly with the events that change it.

            It seems to me the moving the location of ct_panel up should merely necessitate a change in how I refer to it. But it seems that something about the SwipeView or the CalibrationPageForm.ui changes the scope/naming resolution. I'd like to understand what/why that is.

            Julien BJ 1 Reply Last reply
            0
            • Steve FallowsS Steve Fallows

              @Julien-B I'm just trying to get the same behavior with the ct_panel object up one level from where it was. I want to bind the receptorPath property to the text field on the CalibrationPage. I'd prefer not to deal explicitly with the events that change it.

              It seems to me the moving the location of ct_panel up should merely necessitate a change in how I refer to it. But it seems that something about the SwipeView or the CalibrationPageForm.ui changes the scope/naming resolution. I'd like to understand what/why that is.

              Julien BJ Offline
              Julien BJ Offline
              Julien B
              wrote on last edited by Julien B
              #6

              @Steve-Fallows,

              Just to clarify is receptorPath_textField also an id?

              in that case your code

              CTPanel {
                  id: ct_panel
                  Component.onCompleted: {
                      ct_panel.setUp()  // Complete set up of the C++ object
                      console.log("CT Panel component completed.")
                  }
                  receptorPath: receptorPath_textField.text
              }
              

              should work wherever it is placed (in the same qml file).

              if receptorPath_textFieldis is a grouped property from CalibrationPageForm and the id of the page is page

              Have tou tried?

              CalibrationPageForm {
                  id: page
                  receptorPath_textField.text: settings.receptorPath
              }
              CTPanel {
                  id: ct_panel
                  Component.onCompleted: {
                      ct_panel.setUp()  // Complete set up of the C++ object
                      console.log("CT Panel component completed.")
                  }
                  receptorPath: page.receptorPath_textField.text
              }
              
              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