<?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 Consumption of active QQmlQuickWidget nested in QWidget is vastly higher than inactive QQmlQuickWidget (4900 MB vs. 200 MB)]]></title><description><![CDATA[<p dir="auto">Hello Qt-Forum,</p>
<h3>Context:</h3>
<p dir="auto">I am developing a research prototype for a novel interaction concept and computational desktop environment, I currently call <em>Sketchable Interaction</em> (SI).<br />
Currently, SI works only on Debian-based linuxes.<br />
In a nutshell, SI allows users to draw interactive regions on their desktop which carry effects.<br />
Once two or more regions overlap, regions which's effects are compatible to each other apply their effects to each other as well.<br />
In this way, graphical representations and data of files, etc. can be set, modified or deleted.</p>
<p dir="auto">Here are some screenshots to give a visual  example:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/6f822e3e-ce5f-4a5a-8db8-33edd672638c.png" alt="SI-1.png" class=" img-fluid img-markdown" /><br />
Showing Desktop Environment.</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/f40dfc2f-f277-4297-8e39-1492b33e87a3.png" alt="SI-2.png" class=" img-fluid img-markdown" /><br />
Drawing region (blue one) for Opening Folders/Files.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/00428a9d-ceb8-4cb8-ac1b-cc3c82c53dd8.png" alt="SI-3.png" class=" img-fluid img-markdown" /></p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/c1e1687a-e283-4405-8347-f2761758ab4c.png" alt="SI-4.png" class=" img-fluid img-markdown" /><br />
Opended Desktop-Folder by overlapping it with the blue region and drew a Preview File region.</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/ddf791ff-b982-4a32-bf5d-c30f62afc290.png" alt="SI-5.png" class=" img-fluid img-markdown" /><br />
Moved image file (png) with the cat out of the folder.</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/d0745b4a-caf9-41b9-b6eb-d12ca00ff009.png" alt="SI-6.png" class=" img-fluid img-markdown" /><br />
Overlapped image file with the cat with the green region to show a preview of the image.</p>
<p dir="auto">Here's the link to the SI repositories on github: <a href="https://github.com/PDA-UR/Sketchable-Interaction" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/PDA-UR/Sketchable-Interaction</a> and <a href="https://github.com/PDA-UR/Sketchable-Interaction-Plugins" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/PDA-UR/Sketchable-Interaction-Plugins</a></p>
<h3>Technical Status Quo of SI</h3>
<p dir="auto">SI is written in C++ with the current Qt5 and QML versions.<br />
SI-Plugins which represent the effects you saw in the screenshots, are written in python3.7+, with the use of Boost.Python and <strong>do not</strong> use PyQt5.</p>
<p dir="auto">SI opens a MainWindow and every region drawing (everything you see in the screenshots is a region, including the mouse cursor) is a QWidget which is a borderless child of that MainWindow.<br />
In order to do any styling e.g. display textures, like the folder icon, SI uses QML files, represented as QQuickWidgets wich is a borderless child of that QWidget (I am aware of the stacking order problem, but we can ignore that for this question!)<br />
I am able to change QML styling from within SI-Python-Plugins at runtime.<br />
This internally uses QMetaObject to pass a QMap&lt;qstr, QVariant&gt; to a function in the container component.</p>
<pre><code class="language-C++">QMetaObject::invokeMethod(reinterpret_cast&lt;QObject *&gt;(d_view-&gt;rootObject()), "updateData", QGenericReturnArgument(), Q_ARG(QVariant, region-&gt;data()));
</code></pre>
<p dir="auto">I tested this with signals/slots as well, yet was unable to get it working as I intended, the above method does work as intended.<br />
Apparently, this is due to initializing exactly one QQmlEngine, instead of one per QQuickWidget.<br />
This single QQmlEngine has CppOwnership.</p>
<pre><code class="language-C++">    engine = new QQmlEngine(this);
    engine-&gt;setObjectOwnership(engine, QQmlEngine::CppOwnership);
</code></pre>
<h3>The Problem</h3>
<p dir="auto">For testing purposes and performance benchmarking I intend to spawn thousands of regions:<br />
The following screenshots shows 1009 regions (1000 in the center).<br />
This one is with all QML related code deactivated:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/281cec6c-8ce7-4c0e-9dc0-e32b066fba4b.png" alt="SI-1k_regions-without-QML.png" class=" img-fluid img-markdown" /><br />
This yields, according to the tool htop, roughly 200 MB memory consumption.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/c7aa4f61-6a15-4c64-99d4-330d5b62a5b3.png" alt="mem_no_qml.png" class=" img-fluid img-markdown" /><br />
The same example with QML activated:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/2b9e8583-3622-4b14-8cc3-066f6758213e.png" alt="SI-1k_regions-with_QML.png" class=" img-fluid img-markdown" /><br />
This yields roughly 4900 MB memory consumption.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/a1e84b3f-ccc6-47e4-b443-873c344525be.png" alt="mem_qml.png" class=" img-fluid img-markdown" /><br />
The texture used in the yellow regions in the example with QML is a 64x64 px 32-bit RGBA image.<br />
This memory difference really strikes me as odd.</p>
<p dir="auto">The memory required for all images equals 1000 (number of regions) * 64 * 64 (number of pixels) * 4 (number of bytes if 4 channels with 8 bit) = 16,384,000 bytes which are ~16.5 MB. Of course there should be some further overhead per image, yet not 4.8 GB of overhead.</p>
<p dir="auto">I found out via other questions here or other sources that QML apparently needs a lot memory (some call it a <em>memory hog</em>).<br />
Yet, this high difference could stem from my unorthodox usage of Qt5 and QML.</p>
<h3>Question/s</h3>
<p dir="auto">Is there a way to lower this memory consumption, given the current state of the SI software?<br />
Are their alternative approaches I did not come up with?<br />
Is their a flag in Qt5/QML docs I missed which trivializes the problem?</p>
<p dir="auto">Sorry for the lengthy post and thanks in advance for your help.</p>
<p dir="auto">Edits: Typos, Clarity</p>
]]></description><link>https://forum.qt.io/topic/116960/memory-consumption-of-active-qqmlquickwidget-nested-in-qwidget-is-vastly-higher-than-inactive-qqmlquickwidget-4900-mb-vs-200-mb</link><generator>RSS for Node</generator><lastBuildDate>Tue, 27 Oct 2026 22:49:39 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/116960.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 13 Jul 2020 11:00:20 GMT</pubDate><ttl>60</ttl></channel></rss>