Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to load a PDF asynchronously using QtPDF (using threading)?
Qt 6.11 is out! See what's new in the release blog

How to load a PDF asynchronously using QtPDF (using threading)?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 225 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bubu-Droid
    wrote last edited by
    #1

    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):

      QFuture<QPdfDocument*> future = QtConcurrent::run([](){
        QPdfDocument* loadDoc = new QPdfDocument();
        loadDoc->load(ProjectSettings::instance().pdfPath);
        loadDoc->moveToThread(QApplication::instance()->thread());
        return loadDoc;
      });
    
      m_document = future.result();
    
    JonBJ 1 Reply Last reply
    0
    • B Bubu-Droid

      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):

        QFuture<QPdfDocument*> future = QtConcurrent::run([](){
          QPdfDocument* loadDoc = new QPdfDocument();
          loadDoc->load(ProjectSettings::instance().pdfPath);
          loadDoc->moveToThread(QApplication::instance()->thread());
          return loadDoc;
        });
      
        m_document = future.result();
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote last edited by JonB
      #2

      @Bubu-Droid
      Why do you first create https://forum.qt.io/post/839002, to which I have replied, and then this new topic? It is precisely because people answer in one place that we don't want you to raise duplicates.

      I posted there:

      Obviously to start with:

      • QPdfDocument::Error QPdfDocument::error() const (and statusChanged(QPdfDocument::Status status)). This is vital and first thing you should check.
      • Verify ProjectSettings::instance().pdfPath exists.
      • Have you tried multiple/absolute minimal PDF documents?
      • Get rid of any concurrency/moveToThread.
      • Is it safe/sensible to call loadDoc->moveToThread() while loadDoc->load() is running? Even if it is allowed, why/what is the effect of setting off a load before moving to a thread?

      Please pick one or other topic and stick to it.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved