Skip to content

Instantly share code, notes, and snippets.

@stephenquan
Last active March 21, 2018 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenquan/8e109280e83750ac50588d98bc757b0a to your computer and use it in GitHub Desktop.
Save stephenquan/8e109280e83750ac50588d98bc757b0a to your computer and use it in GitHub Desktop.
appstudio-messagehandler-loader-sample.qml
import QtQuick 2.7
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
import ArcGIS.AppFramework 1.0
import ArcGIS.AppFramework.Controls 1.0
Item {
property string errorString: ""
ColumnLayout {
anchors.fill: parent
anchors.margins: 10 * AppFramework.displayScaleFactor
spacing: 10 * AppFramework.displayScaleFactor
RowLayout {
Layout.fillWidth: true
spacing: 10 * AppFramework.displayScaleFactor
TextField {
id: textField
Layout.fillWidth: true
text: "https://gist.githubusercontent.com/stephenquan/e49fda383942fd2a73e4df02a680bcb0/raw/845646c8dc047fa10cef3c23ce3ad97dd244aa38/appstudio-detect-internet.qml"
selectByMouse: true
onAccepted: navigateTo(text)
}
Button {
text: qsTr("Load")
onClicked: navigateTo(textField.text)
}
}
Loader {
id: loader
Layout.fillWidth: true
Layout.fillHeight: true
onStatusChanged: if (status !== Loader.Loading) AppFramework.messageHandler.stop()
}
TextArea {
Layout.fillWidth: true
text: errorString
visible: loader.status === Loader.Error
color: "red"
selectByMouse: true
readOnly: true
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
}
Connections {
target: AppFramework.messageHandler
onMessage: errorString = errorString + msg + "\n"
}
function navigateTo(address) {
errorString = "";
AppFramework.messageHandler.stop();
loader.source = "";
AppFramework.trimComponentCache();
AppFramework.messageHandler.start();
loader.source = address;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment