Skip to content

Instantly share code, notes, and snippets.

@danieloneill
Created November 22, 2017 07:41
Show Gist options
  • Select an option

  • Save danieloneill/235c55abf33b278e64607ed07ff5a27a to your computer and use it in GitHub Desktop.

Select an option

Save danieloneill/235c55abf33b278e64607ed07ff5a27a to your computer and use it in GitHub Desktop.
Qml Reloading technique
import QtQuick 2.7
Item {
Loader {
id: multilevelLoader
anchors.fill: parent
property string sourceUrl: 'ThirdComponent.qml'
function reload()
{
source = sourceUrl + '?' + loader.counter;
}
Component.onCompleted: reload();
Connections {
target: loader
onCounterChanged: multilevelLoader.reload();
}
}
}
import QtQuick 2.7
import QtQuick.Controls 2.2
import QtQuick.Window 2.3
Window {
width: 320
height: 240
visible: true
title: 'Reload Test'
Loader {
id: loader
property int counter: 0
property string sourceUrl: 'OtherComponent.qml'
anchors.fill: parent
function reload()
{
counter++;
source = sourceUrl + '?' + counter;
}
onSourceUrlChanged: reload();
Component.onCompleted: reload();
}
Button {
anchors {
bottom: parent.bottom
right: parent.right
}
text: 'Reload'
onClicked: loader.reload()
}
}
import QtQuick 2.0
Item {
Text {
anchors.centerIn: parent
text: 'And this reloads reliably.'
}
}
@LinArcX
Copy link
Copy Markdown

LinArcX commented Jun 20, 2019

It doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment