Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qml component child of qml engine on different path
Forum Updated to NodeBB v4.3 + New Features

Qml component child of qml engine on different path

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 840 Views 2 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.
  • A Offline
    A Offline
    Arsiero
    wrote on last edited by
    #1

    Hi all!

    I need some soggestion...
    I have some core qml element inside the resource path (qrc:/Foo.qml) and other qml element out of this (file:///home/main.qml)

    The qml engine that I need to use an main.qml similar this:

    Rectangle {
    id: optContainer
    foo {
    id: tmp
    }
    }

    I thought to use a component in that way: QQmlComponent component(pEngine, QUrl(QStringLiteral("qrc:/Foo.qml"))); and after that try to add this component inside the QQmlApplicationEngine... but I don't understand how to do this...

    Any suggestions?? :)

    Thanks a lot

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

      @Arsiero IMO one way would be after creating the object you can set optContainer as its parent using setParentItem.

      QQmlComponent component(engine, QStringLiteral("qrc:/Foo.qml"));
      QQuickItem *childItem = qobject_cast<QQuickItem*>(component.create());
      childItem->setParentItem(containerObj); //This will be optContainer's instance from accessed in C++
      

      157

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

        Thanks for your answer @p3c0 !

        as you suggested the object Foo isn't possible to use inside the Main.qml.

        I found another way... if on the Main.qml import qmc path it's possible to use it:

        import "qrc:/"

        so this work fine for me!

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

          @Arsiero

          as you suggested the object Foo isn't possible to use inside the Main.qml.

          Yeah. It directly injects it from C++ side.

          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