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. Loader child element
Forum Updated to NodeBB v4.3 + New Features

Loader child element

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 4.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.
  • S Offline
    S Offline
    Schneidi
    wrote on last edited by
    #1

    Hi,

    I try to access a loader and assign a source file dynamically using JavaScript. That works fine so far.
    But now I need to set some properties of the item I loaded to the loader element.

    The problem is I don't know how to access the element that was instantiated by the loader.
    Is there some kind of child or whatever property that I can refer to.

    Thanks for help guys

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Schneidi
      wrote on last edited by
      #2

      Oh no thats embarrassing.

      A simple case of reading the docs and everything is fine.

      I didn't read the Loader docs properly.
      If I had I had seen the Item property which holds the instance of the loaded item.

      Sorry for that guys.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Schneidi
        wrote on last edited by
        #3

        Oh boy...

        Ok another problem occurred.

        I have the following procedure.

        The qml item which should be instantiated.
        @import QtQuick 1.0
        import Product 0.1

        Item{
        id:detail_screen
        anchors.fill: parent

        property alias product: m_product
        

        Text {
        id: name
        anchors.fill: parent
        text: m_product.productName
        }

        Product{
        id: m_product
        productName: "foo"

        }
        
        Component.onCompleted:
        

        console.log(product.productName);

        }@

        and the JavaScript function which do that for me.
        @
        function loadDetailScreen(source,product)
        {
        console.log(source);
        select_loader.source = source; //load the qml file shown above
        if(select_loader.status == Loader.Ready)
        {
        select_loader.item.product.productName = "bar";
        }
        console.log(select_loader.item.product.productName); //that actually shows "bar"
        }
        @

        When the loadDetailScreen() function is called the loader instantiates the qml item
        which initially has a productName "foo". But I wanna set this productName after loading to "bar"
        This works pretty well so far. But on screen appears still "foo" as text.

        I tried to set a string property which takes the productName and this worked, but I wanna store these informations directly in the product child item.

        It seems like that the change on the productName property won't be synchronized with the text, which has to display it.

        What could be the problem here ?
        Why does the item show still "foo" although I set it to "bar" after loading ?

        Any ideas ?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          blam
          wrote on last edited by
          #4

          I tried running your code as a standalone example and it worked fine - the Text item does indeed update to display "foo" instead of "bar". Perhaps there is something else in your code that is changing this property after loadDetailScreen() has finished?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Schneidi
            wrote on last edited by
            #5

            Hi blam

            the text item is actually supposed to display "bar" after loadDetailScreen() has finished.
            "foo" is the initial value for the text and should be updated to "bar". Which doesn't seem to happen.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              blam
              wrote on last edited by
              #6

              Sorry, my mistake - I meant to write, it does indeed change to "bar" instead of "foo".

              This is the code that I'm trying:

              • SomeItem.qml
                @

              import QtQuick 1.0

              Item {
              property alias product: m_product

              Text { text: m_product.productName }
              
              Item {
                  id: m_product
                  property string productName: "foo"
              
              }
              

              }
              @

              • main.qml
                @
                import QtQuick 1.0

              Item {
              width: 400; height: 400

              Loader { id: select_loader }
              
              Component.onCompleted: loadDetailScreen("SomeItem.qml")
              
              function loadDetailScreen(source)
              {
                  console.log(source);
                  select_loader.source = source; //load the qml file shown above
                  if(select_loader.status == Loader.Ready)
                  {
                      select_loader.item.product.productName = "bar";
                  }
                  console.log(select_loader.item.product.productName); //that actually shows "bar"
              }
              

              }
              @

              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