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
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30
My Carrier: T-Mobile
Accepted Solution

Calling an element id from one QML file to another?

I feel like I am missing something obvious here so if somebody could please help...

 

I would like to call/manipulate an element that is not in the same qml file as the signal.  So for instance if i have:

 

main.qml:

...

Button{
...
onClicked{
label5.text = "Hello World"
}
}
...

 

otherfile.qml

...

Label{
id: label5
text: ""
}

...

 

How would I do this?  If I do what I have above nothing happens because it is looking for somethng named label5 in main.qml and not looking at otherfile.qml. I assume if this is possible I need to put some additional code in either file to expose the elements to each other... right?

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Developer
Developer
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: Calling an element id from one QML file to another?

signals and slots should allow you to do that:

https://developer.blackberry.com/cascades/documentation/dev/signals_slots/index.html

 

but it works mostly when the two qml files have a parent-child relationship...

Developer
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30
My Carrier: T-Mobile

Re: Calling an element id from one QML file to another?

I understand the basics of signals/slots and if these two elements were in the same QML file it would work just fine but they are in separate files.  So pretty much is there a way to have a signal in main.qml look for a slot in otherfile.qml?

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Highlighted
Regular Contributor
Posts: 56
Registered: ‎08-21-2012
My Device: BB10
My Carrier: RIM

Re: Calling an element id from one QML file to another?

Hi, 

 

You need to provide an alias to that Label. Pushed.qml

import bb.cascades 1.0

Page {
    property alias label5 : label5
    Container {
        layout: DockLayout {}
        Label {
            id: label5
            text: "Hello World"
        }
    }
}

 

 

 Next, you need to attach that qml to the one where you want to access Label5 : main.qml

 

import bb.cascades 1.0

NavigationPane {
    id: nav
    Page {
        Button {
            onClicked: {
                pushed.label5.text = "changed"
                nav.push(pushed)
            }
        }
    }
    attachedObjects: [
        Pushed {
            id: pushed
        }
    ]
}

 Here, I wanted to check whether the text gets changed or not hence Im pushing that qml to see the label.

 

 

Developer
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30
My Carrier: T-Mobile

Re: Calling an element id from one QML file to another?

Megha, works great. Thanks!

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Developer
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30
My Carrier: T-Mobile

Re: Calling an element id from one QML file to another?

So follow up question... Say now I wanted to pass something from main.qml to be read by the Pushed.qml, how would I do that?  I tried having the id's I wanted in main.qml as alias and having main{} as an attached object in my Pushed.qml but that did not work.

 

Thoughts?

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
New Contributor
Posts: 8
Registered: ‎07-08-2013
My Device: BlackBerry Z10
My Carrier: AT&T

Re: Calling an element id from one QML file to another?

[ Edited ]

When I try running that code, there's an error at "Pushed" in the main.qml file and it says "The Pushed component might be an unknown or custom component. Its properties are not validated." Any ideas of why I get this error?

 

EDIT: So it turns out that qml files need to start out with capital letters. Otherwise they will not be recognized when you try to add them to "attachedObjects"

Developer
Posts: 74
Registered: ‎05-31-2013
My Device: BlackBerry Z30

Re: Calling an element id from one QML file to another?


bcs925 wrote:

So follow up question... Say now I wanted to pass something from main.qml to be read by the Pushed.qml, how would I do that?  I tried having the id's I wanted in main.qml as alias and having main{} as an attached object in my Pushed.qml but that did not work.

 

Thoughts?


I want to do this same thing. I can't seem to register main{} as an attached object, since it doesn't begin with a capital letter, and if I change it to Main.qml it won't load. Anyone have ideas?



Like this answer? Give it a
Visit my blog for programming help, guides and common issues.
Developer
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30
My Carrier: T-Mobile

Re: Calling an element id from one QML file to another?

The main.qml should be exposed to all of its attached pages. Meaning if you have "label1" in main.qml you should be able to access that from PageTwo.qml (assuming you don't also have something call "label1" in PageTwo.qml).

 

Full example here: http://www.bbcascades.com/index.php/how-to-s/tutorial-list/65-stack-of-screens-passing-information-a...

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Developer
Posts: 74
Registered: ‎05-31-2013
My Device: BlackBerry Z30

Re: Calling an element id from one QML file to another?

In my main.qml, I have an attachedObject of a WebView, with the id WebView1.

 

In Transfer.qml, I can't access this element. Is it because it's an attachedObject?



Like this answer? Give it a
Visit my blog for programming help, guides and common issues.