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

}

}

相关推荐
TNTLWT14 分钟前
Qt控件:交互控件
开发语言·qt
溟洵3 小时前
【C++ Qt】布局管理器
开发语言·c++·qt
C++ 老炮儿的技术栈4 小时前
自定义CString类与MFC CString类接口对比
c语言·c++·windows·qt·mfc
20242817李臻6 小时前
20242817-李臻-课下作业:Qt和Sqlite
jvm·qt·sqlite
夜松云9 小时前
Qt信号槽机制与UI设计完全指南:从基础原理到实战应用
开发语言·qt·ui·qt designer·布局管理·参数传递·qt信号槽
mahuifa18 小时前
(7)python开发经验
python·qt·pyside6·开发经验
galaxy_strive19 小时前
qtc++ qdebug日志生成
开发语言·c++·qt
TNTLWT19 小时前
Qt功能区:简介与安装
开发语言·qt
凯雀安全1 天前
printspoofer的RPC调用接口的简单代码
qt·网络协议·rpc
六bring个六1 天前
文件系统交互实现
开发语言·c++·qt·交互