Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. qmllint or any alternative to avoid anchor warnings
QtWS25 Last Chance

qmllint or any alternative to avoid anchor warnings

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 3 Posters 485 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pradeep P N
    wrote on 11 Nov 2023, 15:52 last edited by
    #1

    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 a ColumnLayout {} 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 within Top {} 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 using qqmllint which did not help in this case.

    Thanks in advance.

    Pradeep Nimbalkar.
    Upvote the answer(s) that helped you to solve the issue...
    Keep code clean.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 12 Nov 2023, 14:16 last edited by
      #2

      qmllint cannot help here as this programming error.
      Inside the top you reset the anchor

      Top {
      anchors.top : undefined.
      }

      This is the only way.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      1
      • P Pradeep P N has marked this topic as solved on 13 Nov 2023, 09:01
      • K Offline
        K Offline
        KH-219Design
        wrote on 13 Nov 2023, 20:43 last edited by
        #3

        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

        www.219design.com
        Software | Electrical | Mechanical | Product Design

        1 Reply Last reply
        1

        1/3

        11 Nov 2023, 15:52

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved