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

}

}

相关推荐
凤年徐13 小时前
Qt 第三章 常用控件总结
开发语言·qt
草莓熊Lotso15 小时前
Qt 进阶控件实战:下拉框、列表、表格 + 旋钮 / 滑动条全攻略
大数据·c语言·开发语言·c++·人工智能·qt
迎風吹頭髮15 小时前
QT中使用QSqlTableModel快速展示SQLite3数据表(TableView实现)
开发语言·qt·sqlite
ShineWinsu17 小时前
对于Qt:QMediaPlayer和QVideoWidget的解析
开发语言·c++·qt·视频·客户端·qmediaplayer·媒体播放器
li星野21 小时前
Qt 单例配置管理器学习记录:JsonConfigManager 的设计原理与使用示例
开发语言·qt·学习
蓝蓝的代码人1 天前
用 Python、Qt 和 Vue 做一个 Windows 股票看盘工具,观潮的行情小窗与桌面提醒
vue.js·python·qt·开源·桌面应用
ShineWinsu2 天前
对于Qt:QSound的解析
c++·qt·面试·音频·笔试·客户端·qsound
小灰灰搞电子3 天前
QLibrary 类详解:在运行时与共享库对话
qt·qlibrary
敲上瘾3 天前
Qt 主窗口QMainWindow:菜单栏、工具栏、状态栏与浮动窗口等
开发语言·c++·qt·ui·qt6.3
阡陌..3 天前
用 PyQGIS + Qt 做一个简单的 GIS 桌面客户端
开发语言·qt