<?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[Memory leakage when sending image from qml to c++]]></title><description><![CDATA[<p dir="auto"><strong>We have Qquickitem class to display the OpenGL window in Qml</strong><br />
Display::Display()<br />
{<br />
setFlag(QQuickItem::ItemHasContents);<br />
}</p>
<p dir="auto">void Display::setImage(QImage image)<br />
{<br />
im = image;<br />
imageUpdadte = true;<br />
update();<br />
}</p>
<p dir="auto">QSGNode* Display::updatePaintNode(QSGNode* oldNode, QQuickItem::UpdatePaintNodeData* updatePaintNodeData)<br />
{<br />
QSGSimpleTextureNode* node = static_cast&lt;QSGSimpleTextureNode*&gt;(oldNode);<br />
if (!node) {<br />
node = new QSGSimpleTextureNode();</p>
<pre><code>        QSGTexture* texture = window()-&gt;createTextureFromImage(im);
         node-&gt;markDirty(QSGNode::DirtyForceUpdate);
          node-&gt;setTexture(texture);
        node-&gt;setRect(boundingRect());
    }

    if(imageUpdadte==true)
    {
        //QImage im1("D:/S[0]_20201002_203942_848.png");
        QSGTexture* texture = window()-&gt;createTextureFromImage(im);
        node-&gt;markDirty(QSGNode::DirtyForceUpdate);
        node-&gt;setTexture(texture);
        node-&gt;setRect(boundingRect());
        imageUpdadte = false;
        qDebug() &lt;&lt; "updatepaintImage";
    }
    return node;
</code></pre>
<p dir="auto">}</p>
<p dir="auto"><strong>In Main.cpp we have registered as</strong><br />
qmlRegisterType&lt;Display&gt;("display",1,0,"Display");</p>
<p dir="auto"><strong>We have a helper class which contains image</strong><br />
QImage Helper::loadImage()<br />
{<br />
return m_loadImage;<br />
}</p>
<p dir="auto"><strong>Qml Code to display the OpenGL window</strong><br />
import display 1.0<br />
Window {<br />
visible: true<br />
width: 640<br />
height: 480<br />
title: qsTr("Hello World")<br />
Rectangle {<br />
width: parent.width<br />
height: parent.height<br />
clip: true<br />
border.color: "red"</p>
<pre><code>    Display {
        id: dpid
        objectName: "dpobj"
        width: parent.width
        height: parent.height
    }
}
Button {
    text: "press"
    onClicked: {
        dpid.setImage(helper.loadImage)
    }
}
</code></pre>
<p dir="auto">}<br />
We will be getting a continues image to update in OpenGL window. When ever we click the button or new image comes the image gets updated in OpenGL window perfectly.<br />
But the issue is, there is a memory leakage, when ever a new image is sent from qml to C++, on every new image sent the memory gets added up, the memory is not cleared before every new image.<br />
We could visualize that on task manager.<br />
We are using 32 bit msvc compiler.<br />
Could any one help us to overcome from this memory leakage issue?<br />
Also please suggest is there any other way in registering the Display class and to send the image to Display class directly?</p>
]]></description><link>https://forum.qt.io/topic/141631/memory-leakage-when-sending-image-from-qml-to-c</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Jul 2026 03:39:47 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/141631.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 Dec 2022 11:46:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Memory leakage when sending image from qml to c++ on Mon, 02 Jan 2023 08:44:15 GMT]]></title><description><![CDATA[<p dir="auto">There will be a image coming from camera, which needs to be displayed in qml through opengl (Display class).</p>
<p dir="auto">We will be doing some painting activity for image in opengl (Display class).</p>
<p dir="auto">We have imported the registered Display class in main.qml (import display 1.0),<br />
To display the opengl window in main.qml as well as to send the image to opengl (Display class)</p>
<p dir="auto">When ever we click the button "press", the image is sent to opengl(Display class) and it is displayed and it is working fine.</p>
<p dir="auto">But the issue is after every new click, after every new image sent to opengl(Display class).<br />
There is a memory leakage, that is memory is not released after every new image.<br />
We can visualize this in "Task Manager" (Memory gets added up).</p>
<p dir="auto">I tried deleting the old texture, but even though the issue exist.</p>
<p dir="auto">we need help to over come this issue.</p>
]]></description><link>https://forum.qt.io/post/742146</link><guid isPermaLink="true">https://forum.qt.io/post/742146</guid><dc:creator><![CDATA[gowdamnh]]></dc:creator><pubDate>Mon, 02 Jan 2023 08:44:15 GMT</pubDate></item><item><title><![CDATA[Reply to Memory leakage when sending image from qml to c++ on Tue, 20 Dec 2022 13:29:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gowdamnh">@<bdi>gowdamnh</bdi></a> said in <a href="/post/740914">Memory leakage when sending image from qml to c++</a>:</p>
<blockquote>
<p dir="auto">QSGTexture* texture = window()-&gt;createTextureFromImage(im);<br />
node-&gt;markDirty(QSGNode::DirtyForceUpdate);<br />
node-&gt;setTexture(texture);</p>
</blockquote>
<p dir="auto">You should <code>delete</code> the old texture when you set a new one.</p>
<pre><code>auto old = node-&gt;texture();
QSGTexture* texture = window()-&gt;createTextureFromImage(im);
node-&gt;markDirty(QSGNode::DirtyForceUpdate);
node-&gt;setTexture(texture);
delete old;
</code></pre>
<p dir="auto">I don't know what your exact use case is, but in general it should be possible and easier to use:</p>
<ul>
<li>just plain Image component from QML</li>
<li>OR you can use ImageProvider <a href="https://doc.qt.io/qt-5/qquickimageprovider.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qquickimageprovider.html</a></li>
</ul>
<p dir="auto">then you don't have to subclass QQuickItem.</p>
]]></description><link>https://forum.qt.io/post/740926</link><guid isPermaLink="true">https://forum.qt.io/post/740926</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Tue, 20 Dec 2022 13:29:11 GMT</pubDate></item></channel></rss>