qml C++插件plugin.qmltypes

先上图:

在git上看到一个开源的工程,(git地址:https://github.com/machinekoder/QtKnobs) 下载下来后简单的研究了下。

这个工程主要是用C++写插件然后给qml调用。正好自己现在在学习这方面的知识,于是就记录一下。

1.下载并编译

下载后编译会生成三个文件:(这里生成的文件名被我改了)

2.生成 plugin.qmltypes文件

这一步,由于不太熟悉qmlplugindump,踩了不少坑。qmlplugindump 格式如下:

格式:qmlplugindump -nonrelocat Arg1 Arg2 Arg3 Arg4
Arg1 :module[插件]名称
Arg2 :module[插件]版本 
Arg3 :插件所在的父路径
Arg4 :xxx.qmltypes的生成路径,一般是和qmldir一样的路径

我这里生成的信息如下:

E:\QtPro\QML\QtKnobs\examples\testQtKnobs\QtKnobs>qmlplugindump -nonrelocatable  QtKnobs 1.0 E:\QtPro\QML\QtKnobs\examples\testQtKnobs > E:\QtPro\QML\QtKnobs\examples\testQtKnobs\QtKnobs\plugin.qmltypes
QCoreApplication::postEvent: Unexpected null receiver
QCoreApplication::postEvent: Unexpected null receiver
QCoreApplication::postEvent: Unexpected null receiver

生成文件内容如下:(截取了部分内容)

3.新建测试工程,测试源码如下:

import QtQuick 2.4
import QtQuick.Window 2.2
import QtKnobs 1.0


Window {
    visible: true
    width: 800;
    height: 600;

    property int newVal : 0

    Timer {
        interval: 1000; running: true; repeat: true
        onTriggered: newVal = Math.floor((Math.random() * 100) + 0)
    }


    Rectangle {
        anchors.fill: parent;


        Column {
            anchors.left: parent.left
            anchors.leftMargin: 10
            anchors.top: parent.top
            anchors.topMargin: 10
            spacing: 30
            Row {
                spacing: 5

                Knob {
                    width:  100
                    height: 100;
                    style: Knob.Pie
                    pieType: Knob.Flat
                    value: 75
                }

                Knob {
                    width:  100
                    height: 100;
                    style: Knob.Arc
                    value: 25
                    color: "#EF6555"
                }

                Knob {
                    width:  100
                    height: 100;
                    readOnly: true
                    style: Knob.Needle
                    needleType: Knob.Point
                    value: newVal
                    color: "#FEC56B"
                }

                Knob {
                    width:  100
                    height: 100;
                    readOnly: true
                    style: Knob.Pie
                    pieType: Knob.Curve
                    value: newVal
                    color: "#C55186"
                }

                Knob {
                    width:  100
                    height: 100;
                    style: Knob.Needle
                    needleType: Knob.Groove
                    value: 35
                }

                Knob {
                    width:  100
                    height: 100;
                    style: Knob.Needle
                    needleType: Knob.Round
                    value: 88
                    color: "#96040F"
                }
            }

            Row {
                spacing: 5

                Knob {
                    width:  100
                    height: 100;
                    style: Knob.Arc
                    //percent: 50
                    //mode: Knob.Percent
                    color: "#EF6555"
                }

                Knob {
                    width:  100
                    height: 100;
                    style: Knob.Pie
                    pieType: Knob.Curve
                    //percent: 90
                    //mode: Knob.Percent
                    color: "#C55186"
                }

                Knob {
                    width:  100
                    height: 100;
                    style: Knob.Arc
                    value: 2500
                    maximumValue: 5000
                }

                Knob {
                    width:  100
                    height: 100;
                    style: Knob.Pie
                    value: 8563
                    maximumValue: 10000
                    color: "#EF6555"
                }

                Item {
                    width: 200
                    height: 200
                    Knob {
                        width:  100
                        height: 100;
                        style: Knob.Pie
                        pieType: Knob.Curve
                        value: 135
                        maximumValue: 200
                        color: "#D7AAFB"
                    }
                }

                Knob {
                    width:  100
                    height: 100;
                    style: Knob.Pie
                    pieType: Knob.Curve
                    value: 25
                    maximumValue: 100
                    color: "#FF3300"
                    backgroundColor: "black"
                    foregroundColor: "#00FF99"
                    borderColor: "#003399"
                    textColor: "#8D18D7"
                }
            }
        }
    }



}

具体的坑我就懒得写了,可以看我的笔记:

文档:QML插件扩展2(基于C++的插件扩展).no...
链接:http://note.youdao.com/noteshare?id=294f86c78fb006f1b1b78cc430a20d74&sub=6027D5FEADC5411D834955387912CAFC

  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
QML (Qt Quick) 和 .ui.qml 是两种不同的技术,用于开发用户界面。QML 是一种用于创建交互式用户界面的编程语言,它使用 Qt 框架,可以用于开发跨平台的应用程序。而 .ui.qml 是一种设计文件,用于描述应用程序的用户界面,通常使用 Qt Designer 工具创建。 联合开发界面时,可以使用 QML 和 .ui.qml 文件来创建和设计用户界面。QML 文件用于定义应用程序的布局和交互逻辑,而 .ui.qml 文件则用于描述应用程序的视觉外观和交互元素。 以下是使用 QML 和 .ui.qml 联合开发界面的步骤: 1. 使用 Qt Designer 工具创建 .ui.qml 设计文件,使用设计器中的 UI 设计工具创建界面元素和布局。 2. 使用 Qt Creator 工具打开设计文件,并在 QML 文件中使用这些 UI 设计元素。 3. 在 QML 文件中定义应用程序的布局和交互逻辑,例如使用 QML 的各种组件和属性来控制界面元素的显示和交互。 4. 将 QML 文件与应用程序的其他部分集成,例如使用 Qt 的信号和槽机制来处理用户交互事件。 5. 使用 Qt 框架的其他功能来提供应用程序所需的功能和特性。 联合开发界面的优点是能够使用两种不同的方法来描述用户界面,从而实现更好的灵活性和可定制性。此外,QML 语言相对易于学习,可以帮助开发人员快速构建高质量的用户界面。 需要注意的是,联合开发界面需要熟悉 QML 语言和 Qt 框架的相关知识,并能够正确地使用 QML 和 .ui.qml 文件来描述用户界面。同时,还需要考虑应用程序的性能和可扩展性等方面的因素。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Liu-Eleven

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值