<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to use QPaint object in QML?]]></title><description><![CDATA[<p dir="auto">I'm referencing this doc: <a href="http://doc.qt.io/qt-5/qtquick-customitems-painteditem-example.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qtquick-customitems-painteditem-example.html</a> but am still missing a crucial step I believe</p>
<p dir="auto">Basically, I'm making a custom loader using QPaint. I make a class for the custom loader, put all methods in the header and include the paint event in the  corresponding cpp file.</p>
<pre><code>CustomLoader::CustomLoader(QQuickItem *parent)
    : QQuickPaintedItem(parent)
{
Q_ASSERT(m_maxValue&gt;=m_minValue); // make sure max is the same or more than the min
    QWidget::paintEvent(event); // call the base class implementation
    QPainter painter(this); // set a painter to paint on the widget
}

void CustomLoader::paint(QPainter *painter){
}

void CustomLoader::setProgress(int progress) //this sets the percentage of completed the loader is 
{

}

</code></pre>
<p dir="auto">I then use the application engine to setContextProperty</p>
<pre><code>CustomLoader customLoader(NULL);

    engine.rootContext()-&gt;setContextProperty("customLoader", customLoader);
    customLoader.setProgress(50);
</code></pre>
<p dir="auto">And get the following error:</p>
<pre><code>main.cpp:15: error: member access into incomplete type 'QQmlContext'
    engine.rootContext()-&gt;setContextProperty("customLoader", customLoader);
                        
</code></pre>
<p dir="auto">my CustomLoader.qml is simply this:</p>
<pre><code>import QtQuick 2.0

Item {
    width: 300
    height: 300

}
</code></pre>
<p dir="auto">I am very new to this and thus have a few questions.<br />
1.) Any ideas what is causing the error I am receiving about accessing an incomplete type?<br />
2.) How do I pass the CustomLoader paint object to the CustomLoader QML so that it displays in the QML element?</p>
<p dir="auto">Thank you!</p>
]]></description><link>https://forum.qt.io/topic/94271/how-to-use-qpaint-object-in-qml</link><generator>RSS for Node</generator><lastBuildDate>Tue, 16 Jun 2026 21:36:12 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/94271.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 03 Sep 2018 19:26:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to use QPaint object in QML? on Tue, 04 Sep 2018 11:35:11 GMT]]></title><description><![CDATA[<p dir="auto">did you qmlregistertype your new qml type?<br />
<a href="https://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qtqml-cppintegration-definetypes.html</a></p>
<p dir="auto">jens</p>
]]></description><link>https://forum.qt.io/post/479633</link><guid isPermaLink="true">https://forum.qt.io/post/479633</guid><dc:creator><![CDATA[jw23578]]></dc:creator><pubDate>Tue, 04 Sep 2018 11:35:11 GMT</pubDate></item><item><title><![CDATA[Reply to How to use QPaint object in QML? on Tue, 04 Sep 2018 10:21:31 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/abanksdev">@<bdi>abanksdev</bdi></a></p>
<p dir="auto">It is not safe to have a widget inside QQuickPaintedItem since it is not supported to create a QWidget on anything but the GUI thread, and your QQuickPaintedItem might end up painting via the render thread. Therefore you should change it so that you don't need to create a QWidget just for the purpose of painting it in QQuickPaintedItem.</p>
<p dir="auto">In order to at least get the rendering to work, assuming you have changed the QWidget to be a different paint device, such as QImage for example. Then you would reimplement paint() and then use the QPainter passed in to render with. Although I would strongly advise against using the following, but in case it helps you could do:</p>
<pre><code>void CustomLoader::paint(QPainter *painter)
{
    MyWidget w;
    w.render(painter);
}
</code></pre>
<p dir="auto">But that is purely for demostration purposes only.</p>
<p dir="auto">Andy</p>
]]></description><link>https://forum.qt.io/post/479613</link><guid isPermaLink="true">https://forum.qt.io/post/479613</guid><dc:creator><![CDATA[AndyS]]></dc:creator><pubDate>Tue, 04 Sep 2018 10:21:31 GMT</pubDate></item><item><title><![CDATA[Reply to How to use QPaint object in QML? on Mon, 03 Sep 2018 19:45:46 GMT]]></title><description><![CDATA[<p dir="auto">maybe include &lt;QQmlContext&gt; in your main.cpp? . It seems it does not find the definition of the Context class.</p>
<p dir="auto">Look up, definition vs declaration, in a c++ book or online.</p>
]]></description><link>https://forum.qt.io/post/479522</link><guid isPermaLink="true">https://forum.qt.io/post/479522</guid><dc:creator><![CDATA[hsolter]]></dc:creator><pubDate>Mon, 03 Sep 2018 19:45:46 GMT</pubDate></item></channel></rss>