Quantcast
Viewing all articles
Browse latest Browse all 4972

Obtain object type string from QML

You may read about tripple equals (===) in docs: Comparison operators [c-point.com] you are right! I never stop learning. I developed the following example: import QtQuick 2.2 import QtQuick.Controls 1.1   ApplicationWindow {     visible: true     width: 2560     height: 1600     color: "white"       Rectangle {         width: 200         height: 100         color: "red"           Text {             id: mytext             objectName: "MyTextObject"             anchors.centerIn: parent             text: "Hello, World!"         }           MouseArea {             anchors.fill: parent             onClicked:                 {                  parent.color = "blue"                  mytext.text = mytext.objectName == "MyTextObject" ? "YES" : "NO"                 }         }     } } I get the name of the object by objectName method: mytext.objectName in your case you can use: Loader {             sourceComponent: myObj.objectName === "MyObject" ? delegate1 : delegate2 } but you have to assign to your object objectName = “MyObject”

Viewing all articles
Browse latest Browse all 4972

Trending Articles