跨qml通信

****Commet.qml

//加载其他文件中的组件 不需要声明称Component

//1.用loader.item.属性 访问属性

//2.loader.item.方法 访问方法

//3.用loader.item.方法.connect(槽)连接信号

Item {

Loader{

id:loader;

width: 200;

height: 200;

source:"qrc:code/CommetOne.qml"

onLoaded: {
loader.item.initok.connect(dook);
loader.item.testfunc("123");
console.log("load")
item.col = "yellow";
}

}

}

function dook()

{

//清除上一个组件的内存

loader.source="";

loader.source="qrc:code/CommetOne.qml";

console.log('Link ok');

}

****CommetOne.qml

import QtQuick 2.0

Item {

signal initok();

id:com

property var col: "red"

Rectangle{

anchors.fill: parent;

color: col;

Component.onCompleted: {

console.log("***********");

mm.start();

}

TextInput{

width: 100

height: 40

}

}

Timer{

id:mm

running: true;

repeat: true;

interval: 100;

onTriggered: {

console.log('dotime')

initok();

}

}

function testfunc(x)

{

console.log(x);

}

}

相关推荐
YxVoyager1 小时前
Qt C++ :QLayout 布局管理
c++·qt
共享家95277 小时前
QT-常用控件(一)
开发语言·qt
ajassi20007 小时前
开源 C++ QT QML 开发(十二)通讯--TCP客户端
c++·qt·开源
nnnnichijou8 小时前
Qt Quick 3D-机械臂模型显示与交互
qt·3d·交互
长源Gingko11 小时前
Windows中在QTCreator中调试,提示缺少debug information files问题的解决
windows·qt
SundayBear13 小时前
Qt 开发修炼指南:从入门到通透的实战心法
开发语言·qt·嵌入式
ajassi200013 小时前
开源 C++ QT QML 开发(十)通讯--串口
c++·qt·开源
BingeBlog14 小时前
[01] Qt的UI框架选择和对比
开发语言·c++·笔记·qt·ui·开源软件
扶尔魔ocy18 小时前
【QT常用技术讲解】opencv实现摄像头图像检测并裁剪物体
开发语言·qt·opencv
ajassi20001 天前
开源 C++ QT QML 开发(二)工程结构
linux·qt·qml