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. Can't a QML file contain more than one QML components?

Can't a QML file contain more than one QML components?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 660 Views 1 Watching
  • 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.
  • Stan HuangS Offline
    Stan HuangS Offline
    Stan Huang
    wrote on last edited by
    #1

    As title, I used qmlscene to interpret a QML file from a QML book, "Qt5 Cadaques", as below. The qmlscene shows that the error at Line of Text component. I tried some other cases, the same thing. How come? The examples come from the Qt book.

    Rectangle { // our inlined button ui
    id: button
    x: 12; y: 12
    width: 116; height: 26
    color: "lightsteelblue"
    border.color: "slategrey"
    Text {
    anchors.centerIn: parent
    text: "Start"
    }
    MouseArea {
    anchors.fill: parent
    onClicked: {
    status.text = "Button clicked!"
    }
    }
    }
    Text { // text changes when button was clicked
    id: status
    x: 12; y: 76
    width: 116; height: 26
    text: "waiting ..."
    horizontalAlignment: Text.AlignHCenter
    }

    J.HilkJ 1 Reply Last reply
    0
    • Stan HuangS Stan Huang

      As title, I used qmlscene to interpret a QML file from a QML book, "Qt5 Cadaques", as below. The qmlscene shows that the error at Line of Text component. I tried some other cases, the same thing. How come? The examples come from the Qt book.

      Rectangle { // our inlined button ui
      id: button
      x: 12; y: 12
      width: 116; height: 26
      color: "lightsteelblue"
      border.color: "slategrey"
      Text {
      anchors.centerIn: parent
      text: "Start"
      }
      MouseArea {
      anchors.fill: parent
      onClicked: {
      status.text = "Button clicked!"
      }
      }
      }
      Text { // text changes when button was clicked
      id: status
      x: 12; y: 76
      width: 116; height: 26
      text: "waiting ..."
      horizontalAlignment: Text.AlignHCenter
      }

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      Hi @Stan-Huang
      due to how QMl is implemented behind the scenes, a QMl-File must always have 1 single root element.

      your Text Item is a sibling to the Rectangle -> that is not possible


      https://doc.qt.io/qt-5/qtqml-documents-structure.html


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      Stan HuangS 1 Reply Last reply
      1
      • J.HilkJ J.Hilk

        Hi @Stan-Huang
        due to how QMl is implemented behind the scenes, a QMl-File must always have 1 single root element.

        your Text Item is a sibling to the Rectangle -> that is not possible


        https://doc.qt.io/qt-5/qtqml-documents-structure.html

        Stan HuangS Offline
        Stan HuangS Offline
        Stan Huang
        wrote on last edited by
        #3

        @J.Hilk I added another component to contain the two and found it works. Thanks.

        1 Reply Last reply
        0

        • Login

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