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: 125
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia
Accepted Solution

Load a sheet from a QML file

Hi, right now I have a sheet in attachedObjects and  I open it with mySheet.open();

I want to move it in an external QML file to make my code more readable, but it doesn't work. What I have to do?

Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Load a sheet from a QML file

Hi,

If you have something like this:

 

main.qml

attachedObjects: [
        Sheet {
            id: loginSheet
            content: ...
        },

 

Simply move it to another qml:

 

MySheet.qml

Sheet {
  content: ...

 main.qml:

 

attachedObjects: [
        MySheet {
            id: loginSheet
        },

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 125
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: Load a sheet from a QML file

[ Edited ]

ah! when i tried to move it in the external qml, i totally removed the attachedobject entry :Online2long:

Thanks!

 

So, if my code is this:

 

main.qml

attachedObjects: [
            Sheet {
                id: abouthelp
                peekEnabled: false
....

 i create an aboutHelp.qml file, with this: (WITHOUT id)

 

Sheet {
       peekEnabled: false
...

 And then in attachedObjects in main.qml I write this:

attachedObjects: [
        aboutHelp {
            id: abouthelp
        },
...

 where aboutHelp comes from aboutHelp.qml filename, right?

 

edit: works perfectly, thanks! :Flowers:

Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Load a sheet from a QML file

Correct, but component names should start from capital letter, i.e. AboutHelp and AboutHelp.qml

 

If you're using that id internally, it can be kept it in AboutHelp { }

 

Id can be overridden when declaring the component in main.qml, for example:

 

...
AboutHelp { id: dialog1 }, AboutHelp { id: dialog2 }


....

dialog2.doSomething()

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 125
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: Load a sheet from a QML file

[ Edited ]

I'm using that id internally like this

 

Sheet {
    id: hellosheet
    peekEnabled: false
    Page {
        Container {
            onTouch: {
                hellosheet.close();
            }
...

If I remove it from the attached QML, it should be still accessible by internal code, right? 

Otherwise if I leave it it will clash with the main one, I think

 

        attachedObjects: [
            HelloSheet {
                id:hellosheet
            },

 

edit: removed the internal id, hellosheet.close() was still able to close the sheet

Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Load a sheet from a QML file

I think this should work correctly:

 

Sheet {
    id: hellosheet
    peekEnabled: false
    Page {
        Container {
            onTouch: {
                hellosheet.close();
            }
...

 ...

attachedObjects: [
            HelloSheet {
                id:hellosheet   // or any other id
            },

 

When creating the component you can give it any other id.

 

I suggest keeping the id defined inside of component for internal use. While it can be referenced via id of parent element, it's better not to force the user of a component to give it a specific id.

 

 


Andrey Fidrya, @zmeyc on twitter