How to reload qml file in QQuickView

What is the correct way to reload qml file in QQuickView? I am using Qt Quick 2.1 and trying to write a simple program that downloads a qml file and displays it. I am currently doing this by creating a QQuickView, and when I want to reload the qml file, I delete the old one and create a new one. What is the right way to do this? calling QQuickView :: setSource with a new qml file (or a modified qml file) did not work for me.

+6
source share
2 answers

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

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

You can do this in your own ways:

  • Create a main.qml file (the name can be anything) inside which you will actually load and unload other qml files.

  • Then use the qml loader element to upload / download (update if you can) any other file.

+1
source

Source: https://habr.com/ru/post/948199/


All Articles