Menu
Home
Log in / Register
 
Home arrow Computer Science arrow Learn BlackBerry 10 App Development
< Prev   CONTENTS   Next >

QML Basic Types

This section reviews some of the most important QML basic types that you will often use when writing Cascades applications.

n string, int, bool, real, double: The “standard” types supported by most programming languages. A real is a number with a decimal point. A double is a number stored in double precision.

n list: A list type contains a list of objects. In JavaScript, you can use the standard array notation to access the list elements. For example, myList[0]. You can also use the length property for iteration: for (int i=0; i < myList.length; i++ )

{...}.

n enumeration: An enumeration type consists of a set of named values. For example, the LayoutOrientation enumeration, which dictates how controls are displayed on the screen, can take values such as LayoutOrientation. TopToBottom or LayoutOrientation.LeftToRight.

n variant: A generic type that can contain any of the other basic types.

Creating a Custom Control

The best way to learn QML is by designing a custom type or control. This will give you the opportunity to see how the different QML syntactical elements fit together and will also give you some insight on how they are used by the Cascades framework.

If you've worked in a large corporation, chances are that you have already relied on an intranet for locating a person in your organization. This information is usually stored in LDAP directories and accessed by using a client application over an intranet. When you look up a person's entry, you will usually be presented with his surname, first name, job title, employee number, and so forth. You will also be presented with the person's picture so that you can easily recognize him when you attend one of those boring corporate meetings. Now let us imagine that your organization has decided to maintain this information using BlackBerry devices. You have been tasked to design a reusable custom control for displaying and updating a person's entry. Let us start by defining a new QML type called PersonEntry.

1. Create a new standard empty Cascades project and call it CorpDir.

2. In the assets folder of your project, where main.qml is located, create a new QML file called PersonEntry.qml using the Container template (right-click the assets folder, and then select New ➤ QML File).

3. Set the Container control's id to root (see Listing 2-5).

Listing 2-5. PersonEntry.qml

import bb.cascades 1.0

Container{

id: root

}

4. PersonEntry is now a new, albeit minimal, custom type recognized by the QML declarative engine. Also, because PersonEntry's root control is a Container, you can add it to a QML page. Go ahead and modify main.qml as shown in Listing 2-6.

Listing 2-6. main.qml

import bb.cascades 1.0

Page {

PersonEntry {

}

}

 
Found a mistake? Please highlight the word and press Shift + Enter  
< Prev   CONTENTS   Next >
 
Subjects
Accounting
Business & Finance
Communication
Computer Science
Economics
Education
Engineering
Environment
Geography
Health
History
Language & Literature
Law
Management
Marketing
Philosophy
Political science
Psychology
Religion
Sociology
Travel