I've a simple component like this one:
SimpleComponent.qml
Image {
id: root
property url selectedImage: ""
property bool selected: false
states: State {
name: 'selected'
when: selectedImage !== "" && selected
PropertyChanges { target: root; source: selectedImage; }
}
}
If I try to do something like the following, the image source will be replaced by selectedImage
even if the condition should not be true
.
SimpleImplementation.qml
Item {
id: root
SimpleComponent {
id: simpleSwitchImage
source: "/path/to/image.png"
selected: true
}
}
Attaching the following to Component.onCompleted
I've got the commented results:
console.log(
selectedImage, // empty string
selectedImage === "", // false
selectedImage === undefined, // false
selectedImage === null, // false
selectedImage === Qt.resolvedUrl(""), // false
selectedImage.toString(), // empty string
selectedImage.toString() === "", // true
selectedImage.isEmpty, // undefined
selectedImage.empty // undefined
)
According to the documentation the only true
I've got is the absolute path to the resource, is this the correct way to do such a simple check for an empty property of type url
?
isEmpty
orempty
property like QUrl::isEmpty()? Sadly the QML doc is not so generous when it comes to basic QML types.typeof selectedImage === "undefined"
? I have not tried it in this case. I'm also not aware of something likeisEmpty
as I cannot find information about it (yet).selectedImage.isEmpty
orselectedImage.empty
, can you try to log that? See the Qt doc of QUrl I've linked above, but as mentioned there is no documentation for QML url, at least not about properties/functions in any way. Since yourselectedImage
is of type url and not a simple string.undefined
, I've updated the question with this new information.