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

}

}

相关推荐
神仙别闹2 小时前
基于 QT(C++)开发的地铁换乘系统
数据库·c++·qt
C++ 老炮儿的技术栈4 小时前
西门子 S7 常用存储区(I/Q/M/T/C/DB/PI/PQ)
linux·开发语言·c++·windows·qt·io
j7~8 小时前
【Qt】(篇二)《信号与槽:信号和槽的概述,使用、自定义信号和槽、信号与槽的连接方式、信号和槽的其他说明》---详解
qt·信号·qt5·信号与槽··qt creater
Littlehero_1211 天前
QT自定义控件之电气接线图(源码开源)
开发语言·qt
qq762118221 天前
Ubuntu22.04 Qt 调用shell 脚本启动程序,GLFW 初始化失败
qt
蓝悦无人机1 天前
Qt Design Studio(QDS)4.8.2项目文件结构详解
开发语言·qt·qt creator·qds·项目文件结构·qtc
qq_401700411 天前
Qt窗体大小控制从resize到自适应
开发语言·qt
Quz1 天前
QML SwipeView:手势翻页与自定义指示器
qt
Quz1 天前
QML TabBar组件与容器索引的绑定
qt
励志不掉头发的内向程序员1 天前
【LibreCAD 2D架构】鼠标点下的坐标为什么会被“吸”走?LibreCAD 对象捕捉系统解析
开发语言·c++·qt·学习·系统架构