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. How to load a component from qml file in loader

How to load a component from qml file in loader

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.1k 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.
  • A Offline
    A Offline
    av2306
    wrote on last edited by
    #1

    Hi,

    I have component definition in a.qml. I want to load this component in main.qml.

    code snippet:

    a.qml:

    Component {
    id: testa
    Rectangle {
    width: 100
    height: 60
    color: 'red'
    }
    }

    main.qml:
    Loader {
    sourceComponent: testa
    }

    It's throwing error saying reference error. Tried with source:"a.qml". I am doing something wrong.

    Any idea?

    Thanks.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      If you are using different file use source instead of sourceComponent and set it to QML file.

      157

      1 Reply Last reply
      0
      • A Offline
        A Offline
        av2306
        wrote on last edited by
        #3

        Tried with source:“a.qml”

        couldn't load component. If same component code available in main.qml, then it is able to load.

        Any idea.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Try removing the Component from a.qml. Just keep the Rectangle.

          157

          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