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

}

}

相关推荐
程序员-King.1 小时前
【Qt开源项目】— ModbusScope-day 5
开发语言·qt
老秦包你会1 小时前
QT第五课------QT系统相关------线程
开发语言·qt
淼淼7633 小时前
Qt拖动工具栏控件到图页中均匀展示
开发语言·c++·windows·qt
YouEmbedded5 小时前
解码信号与槽(含 QTimer 应用)
qt·定时器·信号与槽
小灰灰搞电子5 小时前
Qt SCXML 模块详解
开发语言·qt
开始了码5 小时前
UDP 协议详解与 Qt 实战应用
qt·网络协议·udp
深蓝海拓20 小时前
PySide6从0开始学习的笔记(三) 布局管理器与尺寸策略
笔记·python·qt·学习·pyqt
꧁坚持很酷꧂21 小时前
Windows安装Qt Creator5.15.2(图文详解)
开发语言·windows·qt
淼淼7631 天前
QT表格与数据
开发语言·qt
小灰灰搞电子1 天前
Qt 实现炫酷锁屏源码分享
开发语言·qt·命令模式