UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    QML : need help so solve a warning

    Scheduled Pinned Locked Moved App Development
    4 Posts 2 Posters 1.5k Views 1 Watching
    Loading More Posts
    • 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.
    • EllypsisE Offline
      Ellypsis
      last edited by

      Hi!
      I'm contributing to the app Mines to learn QML.
      I add a timer and a mine counter to tell how many mine left in the minefield.
      It's promising, but I have a warning when I launch the app after compiling.
      It's about an item Grid inside an item Rectangle (QML speaking).
      Here the code :

      Grid {
          id: statBar
          width: parent.width
          height: units.gu(20)
          anchors {
              bottom: parent.bottom
          }
          //anchors.fill: parent
          horizontalItemAlignment: Grid.AlignHCenter
          verticalItemAlignment: Grid.AlignVCenter
          columns: 2
      
          Rectangle {
              id: time_elapsed_rectangle
              height: parent.height
              width: parent.width/2
              anchors {
                  left: parent.left
                  verticalCenter: parent.verticalCenter
              }
      
              Row {
                  anchors {
                      horizontalCenter: parent.horizontalCenter
                      verticalCenter: parent.verticalCenter
                  }
      
                  Image {
                      id: time_icon
                      anchors {
                          verticalCenter: parent.verticalCenter
                          margins: units.gu(2)
                      }
                      source: "../assets/time.svg"
                  }
                  Rectangle{
                      width: units.gu(8)
                      height: parent.height
                      anchors.verticalCenter: parent.verticalCenter
      
                      Item {
                          Component.onCompleted: reset_timer()
                          Timer {
                              id: timer
                              interval: 500; running: false; repeat: true
                              onTriggered: time.text = minefield.update_time_elapsed()
                          }
                      }
                      Text {
                          id: time
                          anchors {
                              verticalCenter: parent.verticalCenter
                              horizontalCenter: parent.horizontalCenter
                          }
                      }
                  }
              }
          }
      
          Rectangle {
              height: parent.height
              anchors {
                  right: parent.right
                  left: time_elapsed_rectangle.right
                  verticalCenter: parent.verticalCenter
              }
      
              Row {
                  anchors {
                      horizontalCenter: parent.horizontalCenter
                      verticalCenter: parent.verticalCenter
                  }
      
                  Image {
                      id: mine_icon
                      anchors {
                          verticalCenter: parent.verticalCenter
                          margins: units.gu(2)
                      }
                      source: "../assets/mine.svg"
                  }
      
                  Rectangle{
                      width: units.gu(8)
                      height: parent.height
                      anchors.verticalCenter: parent.verticalCenter
      
                      Text {
                          anchors {
                              verticalCenter: parent.verticalCenter
                              horizontalCenter: parent.horizontalCenter
                          }
                          text: minefield.n_flags + "/" + minefield.n_mines
                      }
                  }
              }
          }
      }
      

      And here my warning :
      file:///home/ellypsis/dev/linux_phone/ut_app/Mines/build/tmp/qml/Main.qml:210:13: QML Grid: Cannot specify anchors for items inside Grid. Grid will not function.
      But in fact, the code functions pretty well. But it's not a reason to let a warning in the code.
      Any idea?

      You can find the entire code here : Github - ellypsis/Mines

      1 Reply Last reply Reply Quote 0
      • EllypsisE Offline
        Ellypsis
        last edited by

        I did a work around. I replaced my Grid layout to a rectangle layout.
        Maybe it's a bit dirty, but it works fine.
        New code here : https://github.com/ellypsis/Mines/tree/timer%26mine_counter

        1 Reply Last reply Reply Quote 0
        • mymikeM Offline
          mymike
          last edited by

          you can't specify anchors for items directly inside the Grid. in your case the Rectangle time_elapsed_rectangle has anchors but you have to delete them

          EllypsisE 1 Reply Last reply Reply Quote 0
          • EllypsisE Offline
            Ellypsis @mymike
            last edited by

            @mymike Thanks! I will keep that in mind for future application 😉

            1 Reply Last reply Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post