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 get QQmlEngine from QQuickItem
Forum Updated to NodeBB v4.3 + New Features

How to get QQmlEngine from QQuickItem

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 6.2k 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.
  • H Offline
    H Offline
    hailong
    wrote on last edited by
    #1

    I have a QQuickItem, I want to create QQuickText items dynamically in it according to the text property. Because this QQuickItem is a kind of plugin, so I can't get the QQmlEngine directly from the view(I don't know who will use it, I want it to hehave like a normal qml plugin), how to get QQmlEngine from QQuickItem so I can use QQmlComponent to create QQuickText?

    Bye the way,can I create QQuickText directly? can I use the private header files?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      melghawi
      wrote on last edited by
      #2

      Try:

      @
      QQmlEngine *engine = QQmlEngine::contextForObject(quickItemPointer)->engine();
      @

      Not sure if there is a more direct way to do this. If there isn't then I think there ought to be.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chrisadams
        wrote on last edited by
        #3

        Hi,

        qmlEngine(objectPtr) and qmlContext(objectPtr) are useful for this. They are public, and documented, but for some reason the docs aren't showing up the related methods section of the QQmlEngine documentation.

        Yes, you can include the _p.h headers and use the private types; just include "QT+=quick-private" in your .pro. However, doing that means that you are tied to that particular version of Qt, as there are no binary or source guarantees provided for the private classes.

        Cheers,
        Chris.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          melghawi
          wrote on last edited by
          #4

          Yeah I thought there must be a more direct approach to this, I just couldn't find anything in the docs. Thanks Chris.

          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