<?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 efficiently display almost real-time text (logging) without freezing an ui?]]></title><description><![CDATA[<p dir="auto">Currently I'm using QPlainTextEdit with addPlainText but it doesn't work really well.<br />
For example if I have something like</p>
<pre><code>for (int i = 0; i &lt; n; i++) {
    display i in textedit
}
</code></pre>
<p dir="auto">For n &lt; 1e5 it work ok. But for&gt;1e5 it starts freezing the UI. I tried adding some sort of buffering to the logging widget: i.e. store incoming strings in a <code>QQueue</code> and each 250ms or so (using timer) display them all at once, but it didn't solve the problem. As well as just concatenating strings together instead of a queue.<br />
Also, I tried displaying only fixed amount of messages(about 50) per 200ms but that, although improved situation a bit, still didn't solve the issue completely.<br />
The problem appears to be in <code>appendPlainText</code> invocation which always freezes GUI for a bit.<br />
(btw, I tried replacing it with insertPlainText but didn't see much difference and doc didn't help to clear up what the difference is).</p>
]]></description><link>https://forum.qt.io/topic/76958/how-to-efficiently-display-almost-real-time-text-logging-without-freezing-an-ui</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 12:41:28 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/76958.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 07 Mar 2017 19:59:58 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to efficiently display almost real-time text (logging) without freezing an ui? on Wed, 08 Mar 2017 05:40:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/flashmozzg">@<bdi>flashmozzg</bdi></a> One optimization would be to buffer the log messages and when the buffer reaches some defined size then send it to the QPlainTextEdit. In other words: do not send each and every message but groups of messages. I don't think any human would recognize any difference at that speed.</p>
]]></description><link>https://forum.qt.io/post/380505</link><guid isPermaLink="true">https://forum.qt.io/post/380505</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Wed, 08 Mar 2017 05:40:51 GMT</pubDate></item><item><title><![CDATA[Reply to How to efficiently display almost real-time text (logging) without freezing an ui? on Wed, 08 Mar 2017 01:12:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ambershark">@<bdi>ambershark</bdi></a> said in <a href="/post/380478">How to efficiently display almost real-time text (logging) without freezing an ui?</a>:</p>
<blockquote>
<p dir="auto">What kind of data is this?  That seems like a lot of data to be sending to a GUI control.  They really aren't designed for that level of updates.</p>
</blockquote>
<p dir="auto">Just some logging from some interpretation/evaluation running in another thread.<br />
<code>QPlainTexEdit</code> seems to be barely enough with new added changes so I'll keep that for now, it's rather simple for what it's worth and I was able to push about 200 messages every 50 milliseconds, so it's OK.for now. The problem was that some pathological case like fast evaluation of <code>while(true) {send signal to print something}</code> would make application unresponsive and would require a restart, potentially losing some data. Now it's enough for the most common case.<br />
Though I'd still would like to know if there are some easy performance optimizations without switching to the whole new and different model.</p>
]]></description><link>https://forum.qt.io/post/380484</link><guid isPermaLink="true">https://forum.qt.io/post/380484</guid><dc:creator><![CDATA[flashmozzg]]></dc:creator><pubDate>Wed, 08 Mar 2017 01:12:54 GMT</pubDate></item><item><title><![CDATA[Reply to How to efficiently display almost real-time text (logging) without freezing an ui? on Tue, 07 Mar 2017 23:35:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/flashmozzg">@<bdi>flashmozzg</bdi></a> What kind of data is this?  That seems like a lot of data to be sending to a GUI control.  They really aren't designed for that level of updates.</p>
<p dir="auto">Like <a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> said though you need to use a more optimized widget than a QTextEdit.  You may even need to look into using QGraphicsView or something to utilize the graphics card for rendering on a component like that.  However I would just do the view/model and control what the user actually sees.  That should be nice and fast, especially compared to a QTextEdit which was never intended for the use you using it for.</p>
]]></description><link>https://forum.qt.io/post/380478</link><guid isPermaLink="true">https://forum.qt.io/post/380478</guid><dc:creator><![CDATA[ambershark]]></dc:creator><pubDate>Tue, 07 Mar 2017 23:35:00 GMT</pubDate></item><item><title><![CDATA[Reply to How to efficiently display almost real-time text (logging) without freezing an ui? on Tue, 07 Mar 2017 23:18:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ambershark">@<bdi>ambershark</bdi></a><br />
Sorry, I realize that my example was a bit misleading.<br />
The loop is happening in another (non-GUI) thread and it sends a signal to display some text (like text representation of <code>i</code>) in the QPlainTextEdit.</p>
<p dir="auto">Btw, I tried keeping a queue of incoming messages and then show them one by one, or just appending everything to one big string and then showing it, but I didn't really see much performance difference.</p>
<p dir="auto">Anyway, I was somewhat able to overcome this annoyance by finding the right values <code>n</code> and <code>m</code>  for the number of msgs (<code>n</code>) in the queue processed every <code>m</code> milliseconds. That way at least it doesn't freeze the gui, though the backlog becomes massive.</p>
]]></description><link>https://forum.qt.io/post/380476</link><guid isPermaLink="true">https://forum.qt.io/post/380476</guid><dc:creator><![CDATA[flashmozzg]]></dc:creator><pubDate>Tue, 07 Mar 2017 23:18:11 GMT</pubDate></item><item><title><![CDATA[Reply to How to efficiently display almost real-time text (logging) without freezing an ui? on Tue, 07 Mar 2017 21:43:25 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">To add to <a class="plugin-mentions-user plugin-mentions-a" href="/user/ambershark">@<bdi>ambershark</bdi></a>, one alternative could be to use a <a href="http://doc.qt.io/qt-5/qlistview.html" target="_blank" rel="noopener noreferrer nofollow ugc">QListView</a> and a <a href="http://doc.qt.io/qt-5/qstringlistmodel.html" target="_blank" rel="noopener noreferrer nofollow ugc">QStringListModel</a> rather than a QTextEdit. That way you optimise things a bit more for displaying and scrolling.</p>
<p dir="auto">Hope it helps</p>
]]></description><link>https://forum.qt.io/post/380456</link><guid isPermaLink="true">https://forum.qt.io/post/380456</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 07 Mar 2017 21:43:25 GMT</pubDate></item><item><title><![CDATA[Reply to How to efficiently display almost real-time text (logging) without freezing an ui? on Tue, 07 Mar 2017 20:10:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/flashmozzg">@<bdi>flashmozzg</bdi></a> The problem here is constantly updating the textedit without allowing the system to do anything else (because you're in the for loop).</p>
<p dir="auto">So basically, build up the data you want to display and update the text edit once, like so:</p>
<pre><code>QString myStr;
for (auto i=0;i&lt;n;++i)
{
   myStr += myNewData;
}

textedit-&gt;setPlainText(myStr);
</code></pre>
<p dir="auto">If you need to constantly deliver updates then you should do it via a signal/slot type mechanism and not in a for loop like that.  Any loop will hang a thread until it's done.  So if you had to have the loop you would again build the data in a loop outside the GUI thread, and deliver the updates via a signal to your GUI thread that updates the textedit.</p>
<p dir="auto">Also if you make the data in a textedit huge it will not perform well.  You may need to use a faster view to display it.</p>
]]></description><link>https://forum.qt.io/post/380432</link><guid isPermaLink="true">https://forum.qt.io/post/380432</guid><dc:creator><![CDATA[ambershark]]></dc:creator><pubDate>Tue, 07 Mar 2017 20:10:14 GMT</pubDate></item></channel></rss>