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]Accessing TabView component (accessing children properties of component)
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Accessing TabView component (accessing children properties of component)

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 3 Posters 5.9k 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.
  • K Offline
    K Offline
    khajvah
    wrote on last edited by
    #1

    Dear people,

    I have a qml application which has a TabView. Obviously I have created components to assign them to Tabs. There is a component that consists of 2 textfields. Outside of tabview I have a button. onClick of thay button I need to call a c++ function and pass texts of those 2 textfields. Using textfields' ids don't work, because they are created dynamically. How do I access, for example, textfield's text, which is inside a component assigned to a tabview?

    Optionally, here is brief version of my code:

    @ TabView {
    x: 8
    y: 8

        id:tab
    
        Component.onCompleted: {
    
            addTab("Type", typeComoponent);
            addTab("Unit", unitTab)
    
        }
    
    
    }
    

    @

    One of components:
    @ Component {

        id:typeComoponent
    
        GroupBox{
    
            id: groupbox1
            width: 63.2
    
    
            TextField {
    
                id: typefield
    
            }
    
    
            TextField {
    
                id: baseField
    
            }
    
        }
    
    }
    

    @

    I want to access those from here:
    @
    Button {

        id: saveBtn
        
        onClicked: {
    
            adddial.typeSaveClicked(...); //Have to pass tests of tesfields to this function
    
        }@
    
    1 Reply Last reply
    0
    • K Offline
      K Offline
      khajvah
      wrote on last edited by
      #2

      This is kind of important thing, why isn't anybody answering ?

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jens
        wrote on last edited by
        #3

        There are several ways to do this based on scoping rules. One solution is for instance to share root properties that your text fields update when modified or accepted.

        @import QtQuick.Controls 1.1
        import QtQuick 2.1

        Item {
        width: 500
        height: 500
        property string typeResult
        Label {
        y: 200
        id: saveBtn
        text: "Text field is now " + typeResult
        }
        TabView {
        Component.onCompleted: { addTab("Type", typeComoponent); }
        Component {
        id: typeComoponent
        GroupBox{ TextField { anchors.centerIn: parent ; onTextChanged: typeResult = text} }
        }
        }
        }
        @

        1 Reply Last reply
        0
        • K Offline
          K Offline
          khajvah
          wrote on last edited by
          #4

          I have solved my problem few minutes ago.

          @ Component {

              id:typeComoponent
          
              GroupBox{
          
                  id: groupbox1
                  
                  property alias typeValue: typefield.text
                  property alias unitValue: baseField.text
          
              
                  width: 63.2
          
          
                  TextField {
                       id: typefield
                   }
            
                   TextField {
                       id: baseField
                   }
              }
           }@
          

          and then:
          @

                      adddial.typeSaveClicked(tab.getTab(0).item.typeValue)
          

          @

          In general, I didn't how to access TabView's component (getTab(0).item)

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jens
            wrote on last edited by
            #5

            Just note that you should verify that the "item" property is not null, as tabs get instantiated when they are first shown and not at the time that they are added.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              khajvah
              wrote on last edited by
              #6

              Yes, thanks. I did verify. I just felt it is not important in this case (my question was different) :)

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                With getTab(0) you get first tab? What about active tab, how to get it?

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  khajvah
                  wrote on last edited by
                  #8

                  [quote author="Lepa Brena" date="1389088342"]With getTab(0) you get first tab? What about active tab, how to get it?[/quote]

                  Since every tab has different components, you can't access the active tab directly (if there was a way, there wouldn't be any use in any ways). You can use "currentindex":http://qt-project.org/doc/qt-5/qml-qtquick-controls-tabview.html#currentIndex-prop variable to get the index of tab and then check which tab it is(to be able to use components) and access your tab with gettab().

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    Foolish me.
                    Thank you khajvah.

                    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