[SOLVED] Problems with framecapture example with async JS code

  • Hello,

    I am new to Qt and Webkit and definitely I am doing something wrong. What I need is to programatically save a webpage, preferably both as an image and as HTML. I started with Qt tutorials. When I run the browser examples everything works just fine. My page loads well, aslo the flash plugin is working when I change the EnablePlugins parameter and this is what I need. However, I do not need a UI so I went on with the frame capture example and this is where the problems started.

    Simple pages are captured fine, but when I try to load something more complex (for example http://onet.pl) most of the content is not loaded. After short investigation my guess is that this is because some of the content including some articles, ads etc. is loaded asynchroniosly by a JS code. From what I read about loadFinished signal

    "This signal is independant of script execution or page rendering"

    So here are my two questions. One probably trivial, the other probably not so trivial.

    • How can I modify the framecapture example so it waits a predefined amout of time until the dynamic content is loaded? I tried to put a Sleep() call in the saveResult() function but it does not seem to change anything. I even made a simple test page with one timer displayed by PHP code after the page is loaded and the other timer being a JS timer. No matter how long I sleep, after the page is saved to PNG both times are almost equal.
    • Assuming someone will provide an answer to my first question - how should I determine if my page loaded completely? Are there any good practices on that? Is it possible to check what scripts are still running?


  • Moderators

    Hi @kubaall,
    This SO post probably explains something similar.

  • Thanks p3co, it does indeed answer my second question. I will try it, however my solution should be generic as I will be checking lots of different pages. Waiting a predefined time seems not such a bad idea, especially that I do not have to worry about performance at this point in time. It is just a proof of concept for the moment.

    What about the first question? If I would just want to wait 30s and then save the page? How can I do that?

  • Moderators

    @kubaall In that case you can use QTimer. And when it triggers after 30 secs it will invoke a slot function where in you can save the page.

  • Great, it worked perfectly. Thank you very much for your help!

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.