<?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[Displaying a Large PDF without Freezing the UI Thread]]></title><description><![CDATA[<p dir="auto">Hi everyone,</p>
<p dir="auto">I am having some problems displaying a large PDF file using a Loader. I have a sample code below:</p>
<p dir="auto">When the Load button is pressed in the code below, a large PDF file is displayed using PdfMultiPageView. I also make an AnimatedImage visible when the Loader is loading the component. However, since the PDF is a large file, the UI thread probably freezes when creating the PDF elements.</p>
<p dir="auto">Do you have any suggestions for cases like this?</p>
<p dir="auto">I am aware that using Qt.callLater is useful for operations with loops that take a long time, but this case is a little bit different.</p>
<p dir="auto">Thanks in advance.</p>
<pre><code>import QtQuick
import QtQuick.Pdf
import QtQuick.Controls

Window {
    width: 500
    height: 500

    visible: true
    title: "PdfTest"

    Rectangle {
        anchors.fill:parent

        Loader{
            id: loader
            anchors.fill: parent
            asynchronous: true
            sourceComponent: undefined
            onLoaded: loadingImg.visible = false
        }

        Component{
            id: pmvComp
            PdfMultiPageView{
                document: PdfDocument{ source: 'LARGE_PDF_FILE.pdf'} // some Pdf with 20 MB size
            }
        }

        AnimatedImage {
            id: loadingImg
            anchors.centerIn: parent
            source: "loading.gif"
            width:50
            height:50
            visible:false
        }

        Button{
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.bottom: parent.bottom
            anchors.bottomMargin: 10

            text: loader.sourceComponent == undefined ?  "Load":"Unload"
            onClicked: {

                    if(loader.sourceComponent == undefined){
                        loadingImg.visible = true
                        loader.sourceComponent = pmvComp
                    }
                    else{
                        loader.sourceComponent = undefined
                    }
            }
        }
    }

}
</code></pre>
]]></description><link>https://forum.qt.io/topic/156939/displaying-a-large-pdf-without-freezing-the-ui-thread</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 16:53:17 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/156939.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 29 May 2024 19:28:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Displaying a Large PDF without Freezing the UI Thread on Sat, 11 Jul 2026 18:35:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a></p>
<p dir="auto">Hey, I've figured out the cause. It's being caused by the thumbnail rendering. I commented out the line</p>
<pre><code>  ui-&gt;thumbnailView-&gt;setModel(pdfDocument-&gt;pageModel());
</code></pre>
<p dir="auto">and the PDF is loaded instantly. <s>Maybe loading the thumbnails on a different thread won't freeze the UI?</s> (setModel isn't thread safe it seems). The <code>setModel</code> probably causing problems since the <code>pdfDocument-&gt;pageModel()</code> is huge. Can you please help me out with how I could fix this? The <code>thumbnailView</code> is a <code>QListView</code> btw.</p>
<p dir="auto"><strong>EDIT:</strong> I've set <code>setUniformItemSizes</code> to true and the loading is much faster now (almost instantaneous).</p>
<pre><code>ui-&gt;thumbnailView-&gt;setUniformItemSizes(true);
</code></pre>
<p dir="auto">I think this was the key to making the view load its items faster. But the scrolling in the <code>thumbnailView</code> widget is pretty laggy.</p>
]]></description><link>https://forum.qt.io/post/839109</link><guid isPermaLink="true">https://forum.qt.io/post/839109</guid><dc:creator><![CDATA[Bubu-Droid]]></dc:creator><pubDate>Sat, 11 Jul 2026 18:35:22 GMT</pubDate></item><item><title><![CDATA[Reply to Displaying a Large PDF without Freezing the UI Thread on Sat, 11 Jul 2026 17:51:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bubu-droid">@<bdi>Bubu-Droid</bdi></a> said in <a href="/post/839106">Displaying a Large PDF without Freezing the UI Thread</a>:</p>
<blockquote>
<p dir="auto">qDebug() &lt;&lt; ProjectSettings::instance().pdfDocument-&gt;status();</p>
<p dir="auto">I added this after the load() statement to check what the result is. It's weird that this returns READY even though the UI remains frozen.</p>
</blockquote>
<p dir="auto">You just added this.  <code>load()</code> is asynchronous.  You should start by placing a slot on <a href="https://doc.qt.io/qt-6/qpdfdocument.html#status-prop" target="_blank" rel="noopener noreferrer nofollow ugc">statusChanged(QPdfDocument::Status status)</a> to see what is happening.  Does that show loading and then ready or error or never gets to either?</p>
]]></description><link>https://forum.qt.io/post/839108</link><guid isPermaLink="true">https://forum.qt.io/post/839108</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 11 Jul 2026 17:51:18 GMT</pubDate></item><item><title><![CDATA[Reply to Displaying a Large PDF without Freezing the UI Thread on Sat, 11 Jul 2026 17:45:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bubu-droid">@<bdi>Bubu-Droid</bdi></a><br />
Initially you wrote</p>
<blockquote>
<p dir="auto">it fails to load the PDF</p>
</blockquote>
<p dir="auto">Now you say</p>
<blockquote>
<p dir="auto">What I want to avoid is the freezing of UI when I'm trying to load a large PDF</p>
</blockquote>
<p dir="auto">Which is the case?  Does it fail to load the PDF and you should be looking at <code>error()</code> or does it take rather longer than you want and possibly interfere with UI's responsiveness but if you went and made a coffee it would complete by the time you returned?  These are two very different situations.</p>
]]></description><link>https://forum.qt.io/post/839107</link><guid isPermaLink="true">https://forum.qt.io/post/839107</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 11 Jul 2026 17:45:01 GMT</pubDate></item><item><title><![CDATA[Reply to Displaying a Large PDF without Freezing the UI Thread on Sat, 11 Jul 2026 17:42:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a></p>
<p dir="auto">The PDF path does exist. I've removed the entire threading logic and I'm currently trying to load the PDF document in the main thread. I tried adding a print statement just after <code>pdfDocument-&gt;load()</code> for debugging purposes and noticed that the statement gets printed immediately even though the PDF has not finished loading yet and the UI is frozen.</p>
<p dir="auto">What I want to avoid is the freezing of UI when I'm trying to load a large PDF. I'm using X11 as my display server.</p>
<p dir="auto">The pdfviewer project in Qt examples has the same problem. The UI freezes when I'm trying to load a large PDF.</p>
<p dir="auto"><code>qDebug() &lt;&lt; ProjectSettings::instance().pdfDocument-&gt;status();</code></p>
<p dir="auto">I added this after the <code>load()</code> statement to check what the result is. It's weird that this returns <code>READY</code> even though the UI remains frozen.</p>
]]></description><link>https://forum.qt.io/post/839106</link><guid isPermaLink="true">https://forum.qt.io/post/839106</guid><dc:creator><![CDATA[Bubu-Droid]]></dc:creator><pubDate>Sat, 11 Jul 2026 17:42:03 GMT</pubDate></item><item><title><![CDATA[Reply to Displaying a Large PDF without Freezing the UI Thread on Sat, 04 Jul 2026 11:06:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bubu-droid">@<bdi>Bubu-Droid</bdi></a><br />
Obviously to start with:</p>
<ul>
<li><a href="https://doc.qt.io/qt-6/qpdfdocument.html#error" target="_blank" rel="noopener noreferrer nofollow ugc">QPdfDocument::Error QPdfDocument::error() const</a> (and <a href="https://doc.qt.io/qt-6/qpdfdocument.html#status-prop" target="_blank" rel="noopener noreferrer nofollow ugc">statusChanged(QPdfDocument::Status status)</a>).  This is vital and first thing you should check.</li>
<li>Verify <code>ProjectSettings::instance().pdfPath</code> exists.</li>
<li>Have you tried multiple/absolute minimal PDF documents?</li>
<li>Get rid of any concurrency/moveToThread.</li>
<li>Is it safe/sensible to call <code>loadDoc-&gt;moveToThread()</code> while <code>loadDoc-&gt;load()</code> is running?  Even if it is allowed, why/what is the effect of setting off a load before moving to a thread?</li>
</ul>
]]></description><link>https://forum.qt.io/post/839005</link><guid isPermaLink="true">https://forum.qt.io/post/839005</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 04 Jul 2026 11:06:20 GMT</pubDate></item><item><title><![CDATA[Reply to Displaying a Large PDF without Freezing the UI Thread on Sat, 04 Jul 2026 09:57:49 GMT]]></title><description><![CDATA[<p dir="auto">Hey, can someone please reply to this? I'm trying to load a PDF in a Qt Widget application using threading. Irrespective of what I do, it fails to load the PDF. I tried creating a concurrent thread, made a new QPdfDocument, loaded a PDF into the entity and then moved it to the main thread before returning the pointer. It still doesn't work! Here is an MWE (I know that the PDF loading in this example is synchronous, but even this fails to work - forget about loading the PDF asynchronously):</p>
<pre><code class="language-cpp">  QFuture&lt;QPdfDocument*&gt; future = QtConcurrent::run([](){
    QPdfDocument* loadDoc = new QPdfDocument();
    loadDoc-&gt;load(ProjectSettings::instance().pdfPath);
    loadDoc-&gt;moveToThread(QApplication::instance()-&gt;thread());
    return loadDoc;
  });

  m_document = future.result();
</code></pre>
]]></description><link>https://forum.qt.io/post/839002</link><guid isPermaLink="true">https://forum.qt.io/post/839002</guid><dc:creator><![CDATA[Bubu-Droid]]></dc:creator><pubDate>Sat, 04 Jul 2026 09:57:49 GMT</pubDate></item></channel></rss>