Created
November 22, 2017 07:41
-
-
Save danieloneill/235c55abf33b278e64607ed07ff5a27a to your computer and use it in GitHub Desktop.
Qml Reloading technique
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.0 | |
Item { | |
Text { | |
anchors.centerIn: parent | |
text: 'And this reloads reliably.' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't work.