简体   繁体   English

如何将qml文件重新加载到QQuickView

[英]How to reload qml file to QQuickView

what is the proper way of reloading qml file to QQuickView? 将qml文件重新加载到QQuickView的正确方法是什么? I'm using Qt Quick 2.1 and trying to write a simple program that loads a qml file and displays it. 我正在使用Qt Quick 2.1并尝试编写一个加载qml文件并显示它的简单程序。 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. 目前我正在创建一个QQuickView,当我想重新加载qml文件时,我将删除旧的并创建一个新文件。 What is the proper way of doing this? 这样做的正确方法是什么? calling QQuickView::setSource with new qml file (or changed qml file) didn't worked for me. 使用新的qml文件(或更改的qml文件)调用QQuickView :: setSource并不适用于我。

You can use the following (assuming you are in a subclass of QQuickView ): 您可以使用以下内容(假设您位于QQuickView的子类中):

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

You can do it his ways : 你可以这样做:

  1. Create a main.qml (name can be anything) file, inside which, you will be actually loading and unloading other qml files. 创建一个main.qml(名称可以是任何东西)文件,在其中,您将实际加载和卸载其他qml文件。

  2. Then use the qml loader element to load/unload (refresh if you may) any other file. 然后使用qml loader元素加载/卸载(如果可能,刷新)任何其他文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM