您的位置:首页 > 编程语言 > C语言/C++

[Tips] C++ plugin to QML

2015-08-08 16:51 441 查看
1、使用项目创建工具,创建QtQuick2 Plugin工程。

2、有两个名字很重要。

<pre style="margin-top: 0px; margin-bottom: 0px;"><span style="font-size:18px;"><span style=" color:#008000;">//</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">@uri</span><span style=" color:#c0c0c0;"> </span><span style=" color:#008000;">MyPlugin</span></span>

<span style="font-size:18px;">qmlRegisterType<<strong>ComManager</strong>>(<strong>uri</strong>, 1, 0, "<strong>ComManager</strong>");</span>



QML中的写法是 import MyPlugin 1.0,然后在代码里面写 ComManager{...}。

3、生成dll文件,和qmldir文件。qmldir文件内容如下:

module MyPlugin 

plugin ComManager

两个文件放在一个新建的文件夹下,文件夹名字为MyPlugin

4、调试代码时,把MyPlugin文件夹放在exe文件同级目录下,QML才能install plugin。因为是动态调用嘛~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Qt QML C++ plugin