Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload qml file to QQuickView

Tags:

c++

qt

qml

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.

like image 660
otto Avatar asked Jun 27 '13 07:06

otto


2 Answers

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

QUrl tmp = source();
setSource(QUrl());
engine()->clearComponentCache();
setSource(tmp);
like image 94
Thomas McGuire Avatar answered Sep 28 '22 01:09

Thomas McGuire


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.

  2. Then use the qml loader element to load/unload (refresh if you may) any other file.

like image 35
Amit Tomar Avatar answered Sep 28 '22 00:09

Amit Tomar