Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
TheMarco
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB
My Carrier: Sprint

Architecture question: separate QML files and accessing components

I have a TabbedPane in my main.qml in which I wanted to include a separate QML document for each tab. Now as it turns out, when I do this I'm having trouble accessing items that are in one of the separate QML documents from Javascript in the main.qml file. For example let's say I have:

    Tab {
        title: qsTr("Animation")
        imageSource: "images/icon_animation.png"
        AnimationsPage {
        }
    }

Let's say there's a label with id 'foo' inside AnimationsPage.qml.

In the same page where the tabs live I have a Sheet defined with a WebView component in it. This WebView has a onMessageReceived handler defined in which items inside AnimationsPage.qml get manipulated in certain case.

The problem: This does NOT work. However, when I put all the content for Animationspage directly inside main.qml like:

    Tab {
        title: qsTr("Animation")
        imageSource: "images/icon_animation.png"
        Page {
            // ALL THE STUFF THAT USED TO LIVE IN AnimationsPage.qml
        }
    }

Everything all of a sudden works just fine.

I'd like to have a nice modular approach to this app with all pages that live inside my Tabs in separate documents but it seems I'm forced to include it all in main.qml when I want to perform operations on objects in the included document from within main.qml.

Am I overlooking something here or is this some sort of limitation of QML / Cascades?

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Please use plain text.
Developer
treike
Posts: 18
Registered: ‎09-26-2012
My Device: Developer
My Carrier: T-Mobile

Re: Architecture question: separate QML files and accessing components

Maybe you an approach like stated here would work better? Didn't try it though, just a guess.

Another guess was to to give your Animations an ID, thus being able to access other items via this ID?

 

 

Please use plain text.
Developer
TheMarco
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB
My Carrier: Sprint

Re: Architecture question: separate QML files and accessing components

I did look at this and it seems an interesting approach for larger apps. Mine however is fairly small so I didn't think I'd need to use this. Also, with stuff that isn't even loaded at all times I think there's probably even less chance of the items being accessible :smileyhappy:

I did give everything an ID. But let's say 'myid' is in another QML file I can't seem to perform operations on it from javascript in the main file. It's been driving me insane...

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Please use plain text.
Regular Contributor
_NishantShah
Posts: 76
Registered: ‎07-31-2012
My Device: Blackberry
My Carrier: Vodafone

Re: Architecture question: separate QML files and accessing components

Create alias in Animation Page.

 

For example create alias in Aniamtion Page like this

 

AnimationPage.qml

Container {

id: AnimationPageMainContainer

property alias fooText: foo.text

Label{

id: foo

text: "to be manipulated"

}

}

 

& manipulate label's text in main.qml like this

 

main.qml

Tab {
title: qsTr("Animation")
imageSource: "images/icon_animation.png"

AnimationPage{

id: animationPage

}

}

...

....

...

onMessageReceived: {

animationPage.fooText = "Your text to be set"

}

Please use plain text.
Developer
TheMarco
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB
My Carrier: Sprint

Re: Architecture question: separate QML files and accessing components

I finally got around trying this. It works perfectly. My code is now much nicer and more modular. Thanks a bunch!

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Please use plain text.
Developer
TheMarco
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB
My Carrier: Sprint

Re: Architecture question: separate QML files and accessing components

Actually, scratch that. It's not working.

Getting errors in my log about SomePage.somevar not being defined when I use this technique.

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Please use plain text.