qmllint or any alternative to avoid anchor warnings
-
Hi All,
Small & dirty use case considering below code.
I have a Component which is inteded to sit always on top of its parent when used
// dummy code - Top.qml Rectangle { width: parent?.width; height: 100; color: 'red' anchors.top: parent?.top }
When used it in any other component its straight forward it works.
i.e.Window { width: 100 height: 100 Top { } }
But the user who is using this
Top {}
don't check or have some other logic & start using it in aColumnLayout {}
as below`ColumnLayout { .. Top { ... } Text { ... } Button { ... } }
Which throw the warning for the usage ( which is valid 100% )
QML Rectangle: Detected anchors on an item that is managed by a layout. This is undefined behavior; use Layout.alignment instead.
Removing the
anchors
withinTop {}
works and no warnings, but has to be used when using the Top in other component.Still i just want to check is there a way from QML, that I don't show this warning in log with out changing my present code if possible
Tried usingqqmllint
which did not help in this case.Thanks in advance.
-
qmllint cannot help here as this programming error.
Inside the top you reset the anchorTop {
anchors.top : undefined.
}This is the only way.
-
-
This may or may not be of interest to you. I have previously posted about the mechanism I use for enforcing a "total ban" on QML warnings.
You can see that older post (which is still all accurate and applicable) here:
https://forum.qt.io/topic/113028/is-it-possible-to-use-any-qml-parser-tool