跨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);

}

}

相关推荐
笨笨马甲10 分钟前
附加模块--Qt OpenGL模块功能及架构
开发语言·qt
uyeonashi4 小时前
【QT控件】输入类控件详解
开发语言·c++·qt
galaxy_strive14 小时前
绘制饼图详细过程
开发语言·c++·qt
委婉待续1 天前
Qt的学习(一)
开发语言·qt·学习
笨笨马甲1 天前
Qt Quick Layout功能及架构
开发语言·qt
feiyangqingyun1 天前
Qt/C++开发监控GB28181系统/取流协议/同时支持udp/tcp被动/tcp主动
c++·qt·udp·gb28181
jllws11 天前
Qt学习及使用_第1部分_认识Qt---学习目的及技术准备
qt·c++框架
到点就困告1 天前
海康工业相机SDK二次开发(VS+QT+海康SDK+C++)
数码相机·qt·海康
唐墨1232 天前
android与Qt类比
android·开发语言·qt
道剑剑非道2 天前
QT开发技术【ffmpeg + QAudioOutput】音乐播放器 完善
开发语言·qt·ffmpeg