View Single Post
qwazix's Avatar
Moderator | Posts: 2,622 | Thanked: 5,447 times | Joined on Jan 2010
#5
One thing that bugged me for some days until I figured it out, is how components reference one another.

PageStackWindow, which is in main.qml is your application main window. It has the toolbar, hosts the menu, and nothing else.

Now in this PageStackWindow you can insert pages like this

Code:
PageStackWindow{
    Page {
         Text { text: "page1" }
    }

    Page {
         Text { text: "page2" }
    }
}
Since pages usually hold lots of code it is useful to be in other qml files. Now here comes the question, how do you include external files in QML?

If your file starts with a capital letter, it is a component. All components in the directory you are working in are available just like any other built in component e.g. Button

So the guys at the Qt project, created a component named MainPage whose definition is in MainPage.qml and made an instance of it first thing in our PageStackWindow.

You can call MainPage more than once and you can pass parameters to it. If you add
Code:
property string myPageTitle
in the beginning of MainPage.qml

and

Code:
Text { text: myPageTitle }
inside the Page element in the same file

and modify the declaration in main.qml to look like this

Code:
MainPage { myPageTitle: "page1" }
You will see a page with "page1" written in it.
__________________
Proud coding competition 2012 winner: ρcam
My other apps: speedcrunch N9 N900 Jolla –– contactlaunch –– timenow

Nemo UX blog: Grog
My website: qwazix.com
My job: oob

Last edited by qwazix; 2012-03-30 at 18:22.
 

The Following User Says Thank You to qwazix For This Useful Post: