Tools

Namespaces

Variants

Views

Actions

Search

Contents

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

How to create dynamic QML component by XML

Comments

Hamishwillee - Why not just load the qml directly?

One question though, why not just load the QML as QML directly from the server?

hamishwillee
08:49, 22 August 2011 (EEST)

Zebinluo - Re: Load qml from server directly

If you load the QML from the server directly, Maybe you will have to download the pictures/images as well, This method will increase network flow amount. because the internet url cannot match the local drive diretory,the images are located on local drive.

zebinluo
05:31, 23 August 2011 (EEST)

Croozeus -

Hi Zebinluo,

Interesting article, however I am not sure if I understand your above comment- if the qml file is downloaded directly from the web, you can get rid of the XML parsing. No?
As you said the images are on the the local drive, so the qml can have the local path for images.

Perhaps you can also give it a try with qml files and publish your findings.

By now we develop software according to a DDU mode, i.e: Develop-Deploy-Upgrade. When Software has been deployed, if there are upgrades, we often go to internet and download upgrade packages and then upgrade the software. The UIs are often limited to some pages. With the progress of IT technique, people would think if there is a way to avoid upgrading or we just only upgrade in servers, when people look through the information, the client UI will change by the server design, That is the idea I share with you and I will demonstrate in Qt/QML Meego development.

Introduction

One day I take part in a team to develop the CMB-meego project. I am responsible for the film ticket buying module. When I accept the task. I think at once out to realize it using XmlListModel plus PathView technique to finish it. but when I would complete it, the customer came and said it's not their wish, the Page is limited, when they want to change the style,the page won't change at all, I write the page like below:

We also discuss using webbrowser component. The webbrowser component can't supply increasing user experiences. So if there is a way we define the style and model in server, produce xml document, then we parse the document in client and reproduce the user interface. this is the subject I write today. I name it "How to create dynamic QML component by XML".

In this XML document, we define about ten kinds of element, they are page、header、 hbox、vbox---they represent the container in Qt development,and class represent the css style as html,it define like "cmb2_header1{background:url(:/cmbImages/tube/header_bg3.png)" ,image as a Image in QML, src as source and request as a singal when you click on the image. params as parameter passby etc.
How can we parse this XML document and reunion as a QML page, I study the QML structure and find it is combined with components such as Rectangle、BorderImage、Image、Text etc and layouted by Row、Flow、Column etc. and we have an Item component, it can load a page like below:

Especially,every component is started with "{" and end with "}", these are I think about and I find a kind of solution.
We parse the XML document, when we encounter a container tag such as page、hbox、vbox、gridbox,we product a new page. we use Item to load in its parent page. in pages we have the layout, for example hbox has Row, vbox has Column and gridbox has Flow etc
Now let's see how to produced.

PageQML is class to produce a new page, it has construct function and destructor function, it will produce a page?.qml in the directory passed by strDir parameter,
pageNumber is a static int type, I use it to produce defferent page's id and the page's number replace the "?" above.