Data transfer between item?



  • Page1.qml

    I have four textfields in page1 consists of name , age, DOB etc. The textfield are defined in inside the item. The page are loaded in using loader.

    Page2.qml

    i have four textfield like degree, course, coll, etc.The textfield are defined in inside the item. The page are loaded in using loader.

    page3 .qml

    I want to display the page1 and page2 entered text in page3 in list view. How can i acess the textfield entered data only in page3.



  • Hi,
    You can use the created files as items without using loader. If you want to use loader, this may help you
    http://doc.qt.io/qt-4.8/qml-loader.html. Check "Receiving signals from loaded items".



  • @Tirupathi-Korla

    Thank you for your comments.

    I need to pass the textfield text only from one qml to other. I enter the age, name , DOB entered textfield data in page1 will be displayed in page3.qml. I need to transfer textfield enter data only in one qml to other qml.



  • Hi @eswar

    https://forum.qt.io/topic/72890/textinput-value-retain-in-qml

    continuation of other thread topic,

    You can use one property in Second.qml

    property alias adminInfo: text.text
    
    Rectangle
    {
    
        id:textInfo
        width: 150
        height: 50
        color: "skyblue"
        anchors.top: backButton.bottom
        Text {
            id: text
            font.bold: true
            font.pixelSize: 14
            anchors.centerIn: textInfo
        }
    }
    

    And in main.qml

        MouseArea
        {
            anchors.fill: submitButton
            onClicked: {
                secondPage.visible = true
                subWindowObject.visible = false
                secondPage.adminInfo = textInputObject.text
            }
        }
    

    Where u are sending the value from one main.qml file to another Second.qml file.

    Hope this works,

    Thanks,



  • Hi @Pradeep-Kumar

    I will explain my concept clearly

    Here i have three qml files. The first.qml and second.qml have some textfields.

    first.qml

    item{

    name textfield
    age textfield
    DOB textfield

    }

    second.qml

    Item{

    college textfield
    course textfield
    dept textfield

    }

    third.qml
    {

    display the enter textfield value in any form.
    }

    main.qml

    rectangle{

    Inside the rectangle the load the first , second and third qml pages using stack view.

    }
    the two buttons next and back button appear in every page to switch qml views.

    If i move to third page, the all entered text field text will appear in any view. If i switching the pages, the enter data will be retain in textfield.

    how can i do it?



  • I would recommend to try separating the entered text (data) from the components that display them (textfields in pages 1/2 or plain text in page 3).

    As a first simple approach to achieve that, you can for example add properties for the data to your main.qml:

    Rectangle {
      id: main
    
      // myData property will be available in all sub-items of main
      property alias myData: dataItem 
    
      Item {
        id: dataItem
        property string name: ""
        property string course: ""
        // ... other data properties
      }
    }
    

    In your pages, you can then access the values using e.g. myData.name or myData.course.
    Just display the value in the third page, and make sure to save the value to these properties in the pages where you enter the data.

    This setup also ensures that you do not lose the data when pages are destroyed after you e.g. remove them from the StackView.

    Cheers,
    GT


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.