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

}

}

相关推荐
864记忆14 分钟前
车辆视频检测器linux版对于密码中包含敏感字符的处理方法
linux·qt
努力搬砖的咸鱼42 分钟前
QTSql全解析:从连接到查询的数据库集成指南
数据库·qt
EverestVIP1 小时前
Qt 自带的QSqlDatabase 模块中使用的 SQLite 和 SQLite 官方提供的 C 语言版本(sqlite.org)对比
c语言·qt·sqlite
永不停转1 小时前
C++宏定义中可变参数列表__VA_ARGS__ 及 QT 提供的宏 QT_OVERLOADED_MACRO
c++·qt
追烽少年x2 小时前
Qt中自定义插件和库(1)
qt
我真的不会C2 小时前
Qt中的信号与槽及其自定义
开发语言·qt
蜡笔弄丢了小新4 小时前
E: The package APP needs to be reinstalled, but I can‘t find an archive for it.
qt
byxdaz5 小时前
Qt 中 findChild和findChildren绑定自定义控件
qt
liulun12 小时前
Windows注册鼠标钩子,获取用户选中的文本
c++·windows·qt
我真的不会C16 小时前
Qt中的多种输出方式,信号与槽的基本使用
开发语言·qt