How to get QQmlEngine from QQuickItem
-
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?
-
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.