Results 1 to 3 of 3

Thread: what is QML for?

  1. #1
    Join Date
    Feb 2010
    Posts
    5
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded

    Question what is QML for?

    tried some qml samples with qmlviewer, pretty fancy UI...
    wonder how qml is integrated with other C++ parts?, saw that qml can be loaded into QmlView, but how to link the qml UI to business logic in an application. saw the calculator sample has a js file? is it?

    don't see where QML fit in the whole picture...

    any light on this?

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: what is QML for?

    With QML you can design user interfaces without having to adapt your source code. That means that you could hire a user interface developer who will focus on just the UI. QML (declarative UI) is supposed to help you separate your GUI from the actual functionality. In my view QML isn't supposed to really integrate with C++ code.

    Quote Originally Posted by http://labs.trolltech.com/blogs/2009/05/13/qt-declarative-ui/
    Declarative UI is a way of making fluid user interfaces by describing them in terms of simple elements (Text, Image, Rect,and other QObjects) that are built up into components. The reason it is “declarative” is that rather than the changes in the UI being expressed as imperative code (”set this, set that, do this, do that, …”), they are instead expressed as sets of QObject property expressions (”this width is always half that width”), grouped into states (”when enabled, the properties are …, when disabled, they are …”). The language that enables this is named QML. QML is simple yet powerful. Most of a user interface is described by a simple tree structure of property bindings:
    Qt Code:
    1. import Qt 4.6
    2.  
    3. Rectangle {
    4. width: 200
    5. height: 200
    6. color: "white"
    7. Text {
    8. text: "Hello World"
    9. anchors.centerIn: parent
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    You might want to read the whole blog there.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. The following user says thank you to franz for this useful post:

    happyvalley (4th February 2010)

  4. #3
    Join Date
    Feb 2010
    Posts
    5
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded

    Default Re: what is QML for?

    thanks, franz
    ya, read the blog more carefully this time, was looking for how the controls defined with qml can be linked to the functions,
    for example, on a page, with qml,. could create a fancy button on it, but when I click on it how to trigger the event handler.
    seems the snippet below answered the question.

    ---------------------------------
    import Qt 4.6
    Rectangle {
    id: container
    property string label
    signal clicked
    radius: 5; border.color: "black"
    color: mouse.pressed ? "steelblue" : "lightsteelblue"
    gradient: Gradient {
    GradientStop { position: mouse.pressed ? 1.0 : 0.0; color: "steelblue" }
    GradientStop { position: mouse.pressed ? 0.0 : 1.0; color: "lightsteelblue" }
    }
    MouseRegion { id: mouse; anchors.fill: parent; onClicked: container.clicked() }
    Text { anchors.fill: parent; text: container.label; anchors.centerIn: parent }
    }

    QmlComponent component(qmlEngine, "Button.qml");
    QObject *button = component.create();
    button->setProperty("label", tr("Press Me!"));
    connect(button, SIGNAL(clicked()), this, SIGNAL(buttonClicked()));

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.