如何将 qml 文件重新加载到 QQuickView [英] How to reload qml file to QQuickView

查看:18
本文介绍了如何将 qml 文件重新加载到 QQuickView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 qml 文件重新加载到 QQuickView 的正确方法是什么?我正在使用 Qt Quick 2.1 并尝试编写一个简单的程序来加载 qml 文件并显示它.目前我正在通过创建一个 QQuickView 来做到这一点,当我想重新加载 qml 文件时,我正在删除旧文件并创建一个新文件.这样做的正确方法是什么?使用新的 qml 文件(或更改的 qml 文件)调用 QQuickView::setSource 对我不起作用.

what is the proper way of reloading qml file to QQuickView? I'm using Qt Quick 2.1 and trying to write a simple program that loads a qml file and displays it. Currently I'm doing it by creating a QQuickView and when i want to reload qml file i am deleting the old one and creating a new one. What is the proper way of doing this? calling QQuickView::setSource with new qml file (or changed qml file) didn't worked for me.

推荐答案

你可以使用以下方式(假设你在QQuickView的子类中):

You can use the following (assuming you are in a subclass of QQuickView):

QUrl tmp = source();
setSource(QUrl());
engine()->clearComponentCache();
setSource(tmp);

这篇关于如何将 qml 文件重新加载到 QQuickView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆