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
New Developer
daljit97
Posts: 53
Registered: ‎09-05-2013
My Device: Z10
Accepted Solution

Spilt Code in different qml files

Hello, 

I am a beginner of Cascades, I am coming from QtQuick. I want to ask a simple question: I am developing a little application which make a heavy use of Cascades Page components. Now I have more 20 pages, as far as I understood in Casacades you have to put your pages in attachedobjects and you can't push to a new qml file. Now if I code in the traditional way my main file become very big and hard to maintain. Now is there anyway to put my each Page in a different file and have access to them from the main file?

Please use plain text.
Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Spilt Code in different qml files

There are a number of different ways...

 

http://developer.blackberry.com/native/documentation/cascades/best_practices/dynamic_qml/


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.
Developer
greenmr
Posts: 882
Registered: ‎03-20-2013
My Device: Red LE Developer Z10

Re: Spilt Code in different qml files

Easy... lets say you create MyPage.qml and build your page layout there. Now on your navigation pane all you need is:

 

NavigationPane {
   id: navPane
   attachedObjects: [
      MyPage {
         id: myPage
      }
   ]
   onSomeOrOtherSignal: {
      navPane.push( myPage );
   }
}

You don't need to put anything more in your attached object declaration than an "id:" so you can push it later. Layout and code your page in MyPage.qml then attach it to the NavigationPane by the name of the QML file.

 

Easy.     :Angel:



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Please use plain text.
New Developer
daljit97
Posts: 53
Registered: ‎09-05-2013
My Device: Z10

Re: Spilt Code in different qml files

Thank you very much for the help.
Please use plain text.
Developer
greenmr
Posts: 882
Registered: ‎03-20-2013
My Device: Red LE Developer Z10

Re: Spilt Code in different qml files

Was that directed at me, or BBSJdev? (or both)  :Innocent:


daljit97 wrote:
Thank you very much for the help.





Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Please use plain text.
New Developer
daljit97
Posts: 53
Registered: ‎09-05-2013
My Device: Z10

Re: Spilt Code in different qml files

Both, of course. Thank you :smileyhappy:
Please use plain text.
Developer
greenmr
Posts: 882
Registered: ‎03-20-2013
My Device: Red LE Developer Z10

Re: Spilt Code in different qml files

YVW. I should have mentioned that just because you don't HAVE to declare anything else in your attached object, doesn't mean you can't. If you have properties or functions declared on the page in MyPage.qml you can use them to set up the MyPage instance when you attach it:

 

NavigationPane {
   id: navPane
   attachedObjects: [
      MyPage {
         id: myPage
         myPageProperty: value
      }
   ]
   onSomeOrOtherSignal: {
      myPage.myInitializeFunction();
      navPane.push( myPage );
   }
}

Also, this method works if you want to create the page just before pushing it and destroy it after the pop:

 

NavigationPane {
   id: navPane
   attachedObjects: [
      ComponentDefinition {
         id: myPageDef
         MyPage {
            id: myPage
            objectName: "myPage"
         }
      }
   ]
   onSomeOrOtherSignal: {
      var myPage = myPageDef.createObject();
      navPane.push( myPage );
   }
   onPopTransitionEnded: {
      if ( page.objectName == "myPage" ) {
         page.destroy();
      }
   }
}

And finally, if you don't need to set any page properties in the ComponentDefinition you can do this instead:

 

NavigationPane {
   id: navPane
   attachedObjects: [
      ComponentDefinition {
         id: myPageDef
         source: "MyPage.qml"
      }
   ]
   onSomeOrOtherSignal: {
      var myPage = myPageDef.createObject();
      navPane.push( myPage );
   }
   onPopTransitionEnded: {
      // ---We couldn't set objectName on the page, so just destroy it
      page.destroy();
   }
}

If your page in MyPage.qml can have the objectName property set there instead of in the ComponentDefinition then you can still test the page type before destroying it.

 

CIAO



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Please use plain text.
New Developer
daljit97
Posts: 53
Registered: ‎09-05-2013
My Device: Z10

Re: Spilt Code in different qml files

The last solution is really good! I used that method.
Please use plain text.