Use qml to develop meego applications

Source: Internet
Author: User

What is qml?
?

Qml is a declarative language that describes the application UI, including the application's appearance (menu, button, layout, etc.) and behavior (click event. In qml, the UI interface is described as a tree structure with attribute objects (similar to Dom)

Javascript
Javascript: the definitive guide
). Understanding HTML, CSS, and other Web technologies is helpful, but not necessary.

The previous two paragraphs are officially introduced. For more information about the Chinese tutorials, see the tutorials of the QT technology sharing blog series.
, Qml is actually QT quick
(New features in qt4.7.0) one of the core components: QT quick is a group designed to help developers create on mobile phones, media players, set-top boxes and other portable devices use more and more intuitive, modern, and smooth UI tools. Qt quick includes a rich set of user interface elements, a declarative language (qml) used to describe the user interface and runtime, A group of C ++ APIs used to integrate these high-level features into classic QT applications.

From the official introduction, we can see that QT quick is tailored for the rapid development of mobile platforms. Let's take a look at a practical example: Running meenotes on meego, in addition to the business logic, the UI is implemented using qml.

Meenotes Running Effect

Screen switching (click the asterisk ~)

Running effects in simulators

Meenotes can be found here
Find: Use git to clone & lt; font color = "# ff0000"> QT-components and meenotes
Next, compile QT-components first, which depends on qt4.7. It is the key to using qml to quickly develop the meego application. It implements a set of meego qml modules, you can compile and run meenotes. If it cannot run, check whether com. Is In The QT installation directory. nokia. meego this module (My located at/usr/local/trolltech/Qt-4.7.0/imports/COM/meego) if not, you need to manually execute qmake/make install in src/meego under the decompressed directory of QT-components for compilation and installation.

Let's take a look at the actual code in meenotes.

In the src directorySRC. Pro
The red part is different from the libmeegotouch development:

Template = app

Target = ../meenotes

Libs + =-lqtcomponents


Headers + = models/meenotesmodel. h/

Models/notemodel. h

Sources + = Main. CPP/

Models/meenotesmodel. CPP/

Models/notemodel. cpp

Qt + = declarative


Let's look at main. cpp at the main entry:

# Include "models/meenotesmodel. H"

# Include <qapplication>

# Include <qdeclarativecontext>

# Include <qdeclarativecomponent>


# Include <qdir>

# Include <qtcomponents/qdeclarativewindow. h>

Int main (INT argc, char ** argv)

{

Qapplication app (argc, argv );
App. setapplicationname ("meenotes ");


// Meenotesmodel is a model class

Qmlregistertype <notemodel> ();

Meenotesmodel model;

Model. setsource ("Notes /");

// Where can I find main. qml?

# Ifndef meenotes_resource_dir
Const qdir Dir (qapplication: applicationdirpath ());

Const qurl qmlpath (dir. absolutefilepath ("resource/default/Main. qml "));

# Else
Const qdir Dir (meenotes_resource_dir );
Const qurl qmlpath (dir. absolutefilepath ("Main. qml "));

# Endif
// Create a window that can explain qml running

Qdeclarativewindow window (qmlpath );

Window. rootcontext ()-> setcontextproperty ("meenotes", & model );
Window. window ()-> show ();
Return app.exe C ();

}


View main. qml:

Import QT 4.7

Import com. meego 1.0


Window {

ID: Window

Component. oncompleted :{

Window. nextpage (QT. createcomponent ("notelist. qml "))


}

}


View notelist. qml:


Import QT 4.7

Import com. meego 1.0

Page {

Title: "meenotes"

Actions :[

Action {

Iconid: "icon-m-toolbar-Add" // handle the new note button


Ontriggered :{

VaR note = meenotes. newnote ();

Note. Title = (math. Random ()> 0.5 )? "Cool title! ":"";

Viewnote (note );

}

},

Action {

Iconid: "icon-m-toolbar-favorite-mark" // button processing for horizontal and vertical screen Switching



Ontriggered :{

Screen. Orientation = screen. Orientation = screen. portrait? Screen. Landscape: screen. portrait;

}

}

]

Component {
... ... ... // Omitted

}

Rectangle {

Color: "white"

Anchors. Fill: parent

}

Gridview {

ID: Grid

Anchors. Fill: parent

Model: meenotes

Cellwidth: 250

Cellheight: 210

Delegate: notedelegate

}

Function viewnote (Note ){

Window. nextpage (QT. createcomponent ("note. qml "));

Window. currentpage. Note = note;

}

}

Given that qml is very efficient in writing CSS similar to web pages, it seems that QT designer has been ignored. In fact, desinger of Version 2.01 can be previewed using the meegotouch style, the effect is as follows:


Currently, the designer cannot directly generate the qml file. The desinger of the next version is included in the plan. You can call it QT quick designer, which can already be reflected in QT roadmap:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.