Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Unfortunately the docs are a bit out-of-date (uses Qt4 api), but If you read section <strong>Loading QML Components from C++</strong> here: <a href="https://doc.qt.io/qt-4.8/qtbinding.html" rel="nofollow noreferrer">https://doc.qt.io/qt-4.8/qtbinding.html</a></p> <p>Then you should have something like (with Qt5 api):</p> <pre><code>QQuickView view; view.setSource(QUrl::fromLocalFile("MyView.qml")); QQmlComponent component(view.engine() , QUrl::fromLocalFile("MyItem.qml")); QObject *object = component.create(); </code></pre> <p>This gives you a QObject from a .qml file, but what's missing is how to add this to the view. In qml, items won't get drawn unless they are parented to the view. One way of doing this is to add the item to the root context, like so:</p> <pre><code>QQmlProperty::write(object, "parent" , QVariant::fromValue&lt;QObject*&gt;(view.rootObject())); </code></pre> <p>Also, note (again from the above link): "<em>You should always use QObject::setProperty(), QDeclarativeProperty or QMetaProperty::write() to change a QML property value, to ensure the QML engine is made aware of the property change</em>".</p> <p>Next, we need to set the ownership of the item, otherwise the JavaScript garbage handler can delete your item and you can seg fault randomly.</p> <pre><code>QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership); </code></pre> <p>Finally, you need to remember to delete the object "object". Since it's a QObject you should use:</p> <pre><code>object-&gt;deleteLater(); </code></pre> <p>Hope that helps someone!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload