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. QWebEngineView loadfinished is too quick
Forum Updated to NodeBB v4.3 + New Features

QWebEngineView loadfinished is too quick

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 987 Views 1 Watching
  • 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.
  • C Offline
    C Offline
    coyoteazul
    wrote on last edited by
    #1

    Hi. I'm converting PDF files to images (thumbpics actually) using pdf.js on QWebEngineView, and then rendering them on a QImage and saving it to a file.

    The thing is that of course I have to wait for the view to finish loading before rendering it to the QImage, and I'm having troubles with the signals.

    QWebEngineView::loadFinished triggers before the javascript is done, so I get a blank image.
    My working solution was using QWebEngineView::loadProgress and counting how many times it reads 100.
    It seems that loadProgress returns 100 4 times.
    1st when QWebEngineView has read the javascript, but not executed it (this is when loadFinished triggers)
    2nd when pdf.js has loaded its frame, but not the pdf
    3rd when pdf.js has loaded the pdf
    4th I've no idea what changed here. I see no difference.
    (these events are just suppositions based on what the rendered file shows, not based on documentation or anything more serious)

    Since it seems that by the 3rd 100 pdf.js has loaded the pdf, I should render it at that moment. However I'm not 100% sure that it will always be done by the time it reaches the 3rd 100, or that there will always be a 3rd 100. So it doesn't seem like a good idea to rely on this.

    I just want to make my code more robust. Is there a more reliable way to know when QWebEngineView has actually finished loading all the javascript?

    JonBJ 1 Reply Last reply
    0
    • C coyoteazul

      Hi. I'm converting PDF files to images (thumbpics actually) using pdf.js on QWebEngineView, and then rendering them on a QImage and saving it to a file.

      The thing is that of course I have to wait for the view to finish loading before rendering it to the QImage, and I'm having troubles with the signals.

      QWebEngineView::loadFinished triggers before the javascript is done, so I get a blank image.
      My working solution was using QWebEngineView::loadProgress and counting how many times it reads 100.
      It seems that loadProgress returns 100 4 times.
      1st when QWebEngineView has read the javascript, but not executed it (this is when loadFinished triggers)
      2nd when pdf.js has loaded its frame, but not the pdf
      3rd when pdf.js has loaded the pdf
      4th I've no idea what changed here. I see no difference.
      (these events are just suppositions based on what the rendered file shows, not based on documentation or anything more serious)

      Since it seems that by the 3rd 100 pdf.js has loaded the pdf, I should render it at that moment. However I'm not 100% sure that it will always be done by the time it reaches the 3rd 100, or that there will always be a 3rd 100. So it doesn't seem like a good idea to rely on this.

      I just want to make my code more robust. Is there a more reliable way to know when QWebEngineView has actually finished loading all the javascript?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @coyoteazul
      I don't know anything about what pdf.js does, and what its "frame" is. But you need a signal from the JavaScript once it is "ready", whatever that involves Can you leverage the https://doc.qt.io/qt-5/qwebenginepage.html#runJavaScript-2 overload, so that resultCallback in your host code gets called when pdf.js has done its job and is fully "ready" for you to proceed?

      1 Reply Last reply
      1
      • C Offline
        C Offline
        coyoteazul
        wrote on last edited by
        #3

        I couldn't manage to implement it with runjavascript because pdf.js is way more complex than I can manage at the moment, but your link made me realize that I was ignoring a big part of qwebengine. I think I can use runjavascript to inspect DOM and see if it has already loaded.
        Thank you!

        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