Thursday 2 January 2014

Develop Qml Plugin 1

In this series of articles, I will show how to develop a Qml plugin and use it.
I will use a test.qml to load and use my demo plugin called hello.
Below is the screenshot of result of running test.qml with plugin.
The window get the "hello, world" string from hello plugin and show it.
The code in test.qml looks like so:
import demo 1.0 // import types from the plugin
import QtQuick 2.0
// this class is defined in QML (imports/demo/hello.qml)
Hello {
    // this class is defined in C++ (plugin.cpp)
    MyClick {
        id: click
    }
   
    Text {
        text: click.value
    }
}
From above comments, we know our hello plugin has a module called demo, version is 1.0. It uses the Qml object from hello.qml as a Hello class. Also there a exposed C++ class named MyClick defined in plugin.cpp from dynamic library. 

We can run the test.qml using qmlscene as following:
~/Qt5.2.0/5.2.0/gcc_64/bin/qmlscene -I imports ./test.qml
-I imports indicates that there is a imports sub folder in current folder.
Now we know how to use a plugin from qml file. I will talke about the development of  hello plugin in next article.

No comments:

Followers

Contributors