Showing posts with label Qt QML. Show all posts
Showing posts with label Qt QML. Show all posts

Thursday, May 12, 2016

Qt C++ to Qml Communication using qmlRegisterUncreatableType()


In this article i will discuss about how to access the C++ class  enum types and attributes in qml file using Qt c++ qmlRegisterUncreatableType() template function.

qmlRegisterUncreatableType() will register the c++ class type (derived from QObject) as the non-instantiable type with QML type system. So we can not create object for the class in qml file, but we can use the properties ans enumerated types belongs to this class in qml file.

To access the enum values in qml , we have to make it available to meta-object system with the following macro, Otherwise we cannot access in qml file.
Q_ENUMS(enumType)

To Register the c++ type with qml type system
 qmlRegisterUncreatableType("ModuleName/uri", MajorVersion, MinorVersion, "QmlName", "message");

Here i'm providing the sample code to demonstrate the use of qmlRegisterUncreatableType() to access c++ class attributes and enum types.

Monday, May 27, 2013

Qt QML Introduction and Simple Example Program



QML is declarative language used to develop user interface, is a part of the Qt Quick module. Qt Quick consists of set of technologies including Qml, C++ API's for integrating Qml with Qt application, Qt creator IDE, rum time support.
Qt Quick module comes with the Qt with 4.7 or later versions.

Qml we use elements to draw something on the screen(output) like text, image, rectangle etc.Every element in the qml is like a object. We cal also implement javascript code in side the qml file. Item is the base type for the all the elements.

To start a Qml Application we need to import Qt Quick module with version in the beginning of the every qml file, because the elements we are going to use included in this module. For example the following element displat a rectangle.
Import QtQuick 1.0
Rectangle {
    id: rect
    width: 300
    height: 300
    color: "red"
}