Skip to content

Instantly share code, notes, and snippets.

@curtwagner1984
Created January 10, 2019 19:56
Show Gist options
  • Select an option

  • Save curtwagner1984/4bb39e7ff02e5cef9d02178621cfe054 to your computer and use it in GitHub Desktop.

Select an option

Save curtwagner1984/4bb39e7ff02e5cef9d02178621cfe054 to your computer and use it in GitHub Desktop.
import QtQuick 2.10
import QtQuick.Controls 2.4
import QtQuick.Window 2.2
import QtQuick.Controls.Material 2.3
import QtQuick.Layouts 1.3
ApplicationWindow {
id: appWindow
Material.theme: Material.Dark
title: qsTr("Test QML")
visible: true
width: 640
height: 480
function referenceLoaderText(){
console.log("Loader text:" + myLoader.item.text)
}
Rectangle {
id: myRec
anchors.fill: parent
color: 'grey'
ListView{
anchors.fill: parent
model: 10
delegate: Loader{
id:myLoader
source: "MyButton.qml"
onLoaded: {
console.log("Loader loaded")
referenceLoaderText()
}
}
// Component.onCompleted: {
// console.log("Referencing loader item: " + myLoader.item.text)
// }
}
}
}
@eyllanesc
Copy link
Copy Markdown

You have 10 Loaders since it is inside ListView. Which of these Loaders do you mean when using the id myLoader?
the delegates load components, and the components have local id (they exist only within the component), what is your objective? What do you want to do with the text? You have 10 Loaders with 10 texts, to which of these texts do you want to obtain?

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