Any tool to flag QML file warnings?
-
I’m working with Qt 6.7.2. I’ve just spent several hours tracking down a bug in my qml file. The problem was that a QML Text item specified an id that matched the name of a standard FileDialog property, which caused an error when processing the FileDialog user input. The main.qml was 400+ lines long - here is a brief summary:
Window { [...] Text { id: selectedFile [...] } FileDialog { id: fileDialog [...] onAccepted: { // Expect selectedFile to be url of the last user-selected file console.log('accepted ' + selectedFile); } }
I expected the FileDialog’s selectedFile property would contain the url of the latest user-selected file, e.g. expected the console.log message to look something like this:
accepted file:///home/anon/mb-test-data/Extravert.grd
But instead I see:
accepted QQuickText(0x565143b11010, "selectedFile")
I.e. the Text item with id selectedFile 'shadows' the FileDialog's selectedFile property.
I spent hours debugging this problem. The bug appears obvious in my terse summary of main.qml - but in reality main.qml is 450 lines long! Is there a Qt 6.7 tool that would alert me to this kind of problem? QtCreator did not show any warning or error associated with selectedFile.Thanks!
-
This is a behavioural bug. A QML Type is logged, while its
baseUrl
ortext
property was expected. Probably you wanted to write something like this:console.log('accepted ' + selectedFile.baseUrl)
How should creator know that?
@Axel-Spoerl What OP wrote is what OP wanted to write. FileDialog has a
selectedFile
property.The issue is the weird shadowing of property by an id in an outer scope.
@Tom-asso I'd report it as a bug. It's weird that this is happening. If it can't be fixed due to some limitation, it should at least output a qmllint warning.
-
This is a behavioural bug. A QML Type is logged, while its
baseUrl
ortext
property was expected. Probably you wanted to write something like this:console.log('accepted ' + selectedFile.baseUrl)
How should creator know that?
-
This is a behavioural bug. A QML Type is logged, while its
baseUrl
ortext
property was expected. Probably you wanted to write something like this:console.log('accepted ' + selectedFile.baseUrl)
How should creator know that?
@Axel-Spoerl What OP wrote is what OP wanted to write. FileDialog has a
selectedFile
property.The issue is the weird shadowing of property by an id in an outer scope.
@Tom-asso I'd report it as a bug. It's weird that this is happening. If it can't be fixed due to some limitation, it should at least output a qmllint warning.
-
@Axel-Spoerl What OP wrote is what OP wanted to write. FileDialog has a
selectedFile
property.The issue is the weird shadowing of property by an id in an outer scope.
@Tom-asso I'd report it as a bug. It's weird that this is happening. If it can't be fixed due to some limitation, it should at least output a qmllint warning.
-
T Tom asso has marked this topic as solved on
-
I obviously overlooked this one.
The answer is no, there isn’t such an ambiguity warning. That said, an id from an outer scope would always shadow properties, because the outer scope is imported after the object has been instantiated. That’s not a bug. But you could add a suggestion to warn about such cases. -
@GrecKo , @Axel-Spoerl - I see about 20 projects to select from at the bug tracker - which one is appropriate in this case? Thanks
-
Project is QTBUG.
Issue type should be Suggestion. -