Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. A problem transfering a parameter through a loader.

A problem transfering a parameter through a loader.

Scheduled Pinned Locked Moved Qt Creator and other tools
3 Posts 2 Posters 7.5k 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.
  • AlicemirrorA Offline
    AlicemirrorA Offline
    Alicemirror
    wrote on last edited by
    #1

    Hi to all,

    i am experiencing a strange problem with the loader mechanism.

    The calling document instantiates the loader and pass to it a series of properties defined in the loader QML document. Here is a small example showing the mechanism:

    MyApp.qml includes

    @
    Item {
    id: appItem

    // Properties to customize the loader document
    property string theme: "xxx"
    property string title: "The object title"

    [...]

    // Loader component instance
    MyLoader {
    id: loaderInstance

    // Properties assignement
    theme: appItem.theme
    title: appaItem.title
    
    [... other stuff ...]
    
    // Absolute document name
    obj: "DocToLoad"
    

    }
    @

    Thus MyLoader.qml is defined as follows:

    @
    Item {
    id: docLoader

    property string theme: ""
    property string title: ""
    property string obj: ""

    Loader {
    id: loadObj

    [... various stuff ...]
    function getTheme() { return docLoader.theme; }
    function getTitle() { return docLoader.title; }
    
    source: docLoader.obj + ".qml"
    

    [... code managing component signals ...]
    }
    @

    The problem happens in the loaded object. Take in account that despite this example there is a lot of other parameters passed from the calling application to the destination component throught the loader and all the other works.
    The DocToLoad.qml is defined as follows:

    @
    Item {
    id: loadableObject

    [... the loadable object code ...]

    text {
    id: myText

    [ ...]
    
    text: loadObj.getTitle();
    

    }

    Image {
    id: myImage

    source: "images/'+ loadObj.getTheme() + "/myPicture.png"
    
    [....]
    

    }
    @

    All the parameters passed transparently throught the loader to the loadable object from the calling application works fine including file names.
    The console error that I get is something like
    @
    Could not find the image "images//myPicture.png"
    @
    just as the theme property is not passed at all. Instead the theme property works if in MyApp.qml I assign explicitly the value to the loadObj.theme property, e.g.

    @
    // Loader component instance
    MyLoader {
    id: loaderInstance

    // Properties assignement
    theme: "xxx"
    title: appaItem.title
    
    [... other stuff ...]
    
    // Absolute document name
    obj: "DocToLoad"
    

    }
    @

    In any other way this particular custom property don't work at all. Using loaders intensively this means to replicate the string instead of using a property.

    Any help is appreciated.

    Cheers :)

    Enrico Miglino (aka Alicemirror)
    Balearic Dynamics
    Islas Baleares, Ibiza (Spain)
    www.balearicdynamics.com

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thisisbhaskar
      wrote on last edited by
      #2

      I don't know if I understood your question correctly.. but did you try aliases rather than normal properties.

      @
      // Properties to customize the loader document
      property string theme: "xxx"
      property string title: "The object title"
      @

      to

      @
      // Properties to customize the loader document
      property alias theme: loaderInstance.them
      property alias title: loaderInstance.title

      Component.onCompleted: {
      // assign the values here...
      }
      @

      1 Reply Last reply
      0
      • AlicemirrorA Offline
        AlicemirrorA Offline
        Alicemirror
        wrote on last edited by
        #3

        Thank you very much Vijay, it is a good test.

        What it is needed is to define the (theme) property once and apply it in many different loader instances. The alias assignement do the opposite as I have interpreted: you assign a alias for every instance, that is what I avoid. It is possible that I have misunderstood this method ?

        The real solution I missed probably is Component.onCompleted { ... } This can be the reason of the parameter is not passed correctly.

        Enrico Miglino (aka Alicemirror)
        Balearic Dynamics
        Islas Baleares, Ibiza (Spain)
        www.balearicdynamics.com

        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