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

}

}

相关推荐
残醉1 天前
QT的拖拽功能
qt
蒋星熠1 天前
QT项目 -仿QQ音乐的音乐播放器(第五节)
开发语言·qt
冬停2 天前
解决 Qt 网络 SSL 报错:`cannot call unresolved function` 的终极指南
网络·qt·ssl
mct1232 天前
QUdpSocket发送组播和接受组播数据
qt·组播
火山上的企鹅2 天前
Qt Quick 之动态旋转刻度盘(无人机中指南针 Demo )
qt·无人机·cocos2d
是小峰呀2 天前
QT+opencv+yolov8推理
开发语言·qt·yolo
GUIQU.2 天前
【QT】概述
开发语言·c++·qt
茉莉玫瑰花茶2 天前
Qt 常用控件 - 5
开发语言·qt
残醉2 天前
QT自定义控件
qt
啊森要自信3 天前
【QT】常⽤控件详解(四)常用显示类控件类 Label && LCDNumber && ProgressBar && Calendar Widget
开发语言·数据库·c++·qt·qt6.3