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. [SOLVED] Load Component on signal
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Load Component on signal

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.3k 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.
  • M Offline
    M Offline
    MaxL
    wrote on last edited by
    #1

    Hi everyone,

    I have been trying to create a component when a signal is emitted (for instance on the onClicked of a MouseArea, a Rectangle is fully created ). I have been trying to use Loaders but without success.

    If anyone of you has any idea on the matter, I would really appreciate it.
    Thanks

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

      Hi,

      Using Loader it should work.
      Can you show how you were trying to load through Loader ?

      157

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MaxL
        wrote on last edited by
        #3

        @
        Item
        {
        id: root
        MouseArea
        {
        anchors.fill: parent
        onClicked:
        Loader
        {
        sourceComponent: myRectangle
        }
        }
        Component
        {
        id: myRectangle
        Rectangle
        {
        height: root.height / 2
        width: root.width / 2
        anchors.centerIn: parent
        color: "blue"
        }
        }
        }

        @

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

          You are using the Loader incorrectly. One of the correct way is to load the component for Loader onClick like this,
          @
          Item
          {
          id: root
          width: 400
          height: 400
          MouseArea
          {
          anchors.fill: parent
          onClicked: loader.sourceComponent = myRectangle
          }

          Loader
          {
              id: loader
              anchors.centerIn: parent
          }
          
          Component
          {
              id: myRectangle
              Rectangle
              {
                  height: root.height/2
                  width: root.width / 2
                  color: "blue"
              }
          }
          

          }
          @

          Have a look at "Loader":http://qt-project.org/doc/qt-5/qml-qtquick-loader.html. There are many examples of how to use it.

          157

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MaxL
            wrote on last edited by
            #5

            Tanks :)

            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