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?
QtWS25 Last Chance

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.
  • S Offline
    S Offline
    Steve Fallows
    wrote on 17 Oct 2016, 14:03 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 17 Oct 2016, 14:20 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
      • S Offline
        S Offline
        Steve Fallows
        wrote on 17 Oct 2016, 14:42 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.

        J 1 Reply Last reply 17 Oct 2016, 14:57
        0
        • S Steve Fallows
          17 Oct 2016, 14:42

          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.

          J Offline
          J Offline
          Julien B
          wrote on 17 Oct 2016, 14:57 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?

          S 1 Reply Last reply 18 Oct 2016, 14:11
          0
          • J Julien B
            17 Oct 2016, 14:57

            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?

            S Offline
            S Offline
            Steve Fallows
            wrote on 18 Oct 2016, 14:11 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.

            J 1 Reply Last reply 18 Oct 2016, 14:33
            0
            • S Steve Fallows
              18 Oct 2016, 14:11

              @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.

              J Offline
              J Offline
              Julien B
              wrote on 18 Oct 2016, 14:33 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

              2/6

              17 Oct 2016, 14:20

              4 unread
              • Login

              • Login or register to search.
              2 out of 6
              • First post
                2/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved