[SOLVED]How to access items/properties from within Component{} element??? (Using Ubuntu's ComposerSheet and PopupUtils)



  • I have a "ComposerSheet":http://developer.ubuntu.com/api/ubuntu-12.10/qml/mobile/qml-ubuntu-components-popups0-composersheet.html, which I'm using PopupUtils.show to display, for those that don't know PopupUtils requires it to be in a component like so:
    @
    Component {
    id: dialog
    ComposerSheet {
    //Other stuff goes here
    }
    }
    @

    Then you call PopupUtils.show(dialog); and it pops up, however because it's required to be in a Component{} there doesn't seem to be a way to access things from within, I have a Label in my ComposerSheet, and I need to access myLabel.text, but I can't figure it out for the life of me. I know Component{}s are supposed to be completely encapsulated, so how do you access items from them when they are loaded? Is anyone familiar with PopupUtils? Is there maybe another argument I can pass PopupUtils.show that will pass properties to it? I just can't figure it out and it's getting extremely frustrating, how are we supposed to use Ubuntu Popovers when they are completely encapsulated and we can't pass any info to them??? There has to be a way or they would be completely pointless.

    Sorry if I seem frustrated, I am, I really appreciate any help anyone can provide.


  • Moderators

    You are loading (instantiating) the component somewhere: you need to access it through that object.

    For example, if you have used Loader to load your Component, you would need to access it like this:
    @
    Component {
    id: me
    // some code
    }

    Loader {
    sourceComponent: me
    onLoaded: console.log(item.children().size())
    }
    @



  • Well, I managed to figure it out, and it's actually extremely simple. I decided to look for Ubuntu's QML and JS files, and I found them under /usr/lib/x86_64-linux-gnu/qt5/qml/Ubuntu/Components, I opened up popupUtils.js to study it's open() function, and, of course, it simply returns the object --__--
    Yes, it's that simple, so instead of just calling @PopupUtils.open(myComponent)@

    you call
    @dialog = PopupUtils.open(myComponent)@

    Then you can just use use
    @dialog.myLabel.text = "MyText" //myLabel is a property alias pointing at a Label item@

    The problem is Ubuntu doesn't have it well documented yet, (well, popupUtils.js isn't documented at all).


Log in to reply
 

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