1 Star 1 Fork 0

黑塞 / QMLSignalSlot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

QMLSignalSlot

介绍

这是 一个描述 c++与 QML 通过信号槽的形式链接

讲解

QML

import QtQuick 2.4 Rectangle {

    id: rectangle1
    signal receiveText(string str)    // c++ 发送信号, qml 接收
    signal sendText(string str)       // qml 发送信号, c++ 接收
    Rectangle
    {
        anchors.fill: parent
        color:  "red"
        radius: 10
        Rectangle{
            id:reg
            width: 100
            height: 100
            anchors.centerIn: parent
            radius: 50
            color: "#cccccc"
            Text {
                id: name
                anchors.centerIn: parent
                font.pixelSize: 18
                font.bold: true
                text: qsTr("")
            }
            MouseArea
            {
                anchors.fill: parent
                onClicked:
                {
                    sendText("123456")  // 鼠标点击 发送信号
                    name.text = "Send"
                    num.start()
                }
            }
            NumberAnimation{
                id:num
                target: reg
                property: "scale"
                from:1
                to:0.3
                duration: 2000
            }
            NumberAnimation{
                id:num1
                target: reg
                property: "scale"
                to:1
                duration: 2000
            }
        }
    }
    onReceiveText:   // 当 c++ 发送信号, qml 接收
    {
        name.text = "Recive"
        console.log("aaaaaaaaaaaaaaaaaaaaaaa")
        num1.start()
    }
}

c++

QQuickItem *item = ui->quickWidget->rootObject();

connect((QObject*)(item),SIGNAL(sendText(QString)),this,SLOT(receiveFromQml(QString)));
//  这里qml 的槽函数, 是通过qnl 的信号来触发的。 所以只能通过按钮的信号来触发 qml 的信号
connect(this,SIGNAL(sendToQml(QString)),(QObject*)(item),SIGNAL(receiveText(QString)));
// c++ 按钮点击发送信号。 
connect(ui->pushButton,&QPushButton::clicked,[this]
{
    emit sendToQml("yangsen");
});

空文件

简介

暂无描述 展开 收起
C++
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C++
1
https://gitee.com/kamenqing/qml_signalslot.git
git@gitee.com:kamenqing/qml_signalslot.git
kamenqing
qml_signalslot
QMLSignalSlot
master

搜索帮助