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

}

}

相关推荐
娇娇yyyyyy19 小时前
QT编程(10): QLineEdit
开发语言·qt
墨月白21 小时前
[QT]浮点数转换成4个字节的十六进制(IEEE 754标准)
qt·ieee
小温冲冲1 天前
QML vs Qt Widgets:深度对比与选型实战指南
开发语言·c++·qt
小温冲冲1 天前
如何在Visual Studio中创建QML工程
c++·qt·visual studio
leaves falling1 天前
Qt 项目:计算圆面积
开发语言·qt
( ⩌ - ⩌ )1 天前
4.OpenGL纹理贴图
qt·opengl·纹理
娇娇yyyyyy1 天前
QT编程(9): QTextEdit
前端·qt
森G1 天前
18、QFile类---------QT基础
qt
混分巨兽龙某某1 天前
基于ESP32与Qt Creator的WIFI空间透视项目(代码开源)
qt·嵌入式·esp32·wifi空间透视
A10169330711 天前
QT数据库(三):QSqlQuery使用
数据库·qt·oracle