Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-37377

Accessing QWebView elements on loadingFinished(true) signal fails

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • P3: Somewhat important
    • None
    • 5.2.1
    • WebKit
    • None

    Description

      I experienced a strange behaviour of QWebView when writing a web crawler application. It required a lot of effort to find out what is happening.

      The application does the following:

      1. Create a QWebView object and connect a slot to the loadingFinished signal.
      2. In the mention slot (and ok==true) it searches for an image and writes it geometry to the debug console. e.g. :

       webView.page()->mainFrame()->findFirstElement("img[alt][width][height][src$='.jpg']").geometry(); 

      3. Call setUrl() using an existing webpage URL.

      The first time this works fine and the expected geometry is printed. The second time (and all succeeding retries with the same URL) it find the right img element (with correct src) but prints an invalid geometry (0,0 0x0).

      When comparing

       webView.page()->totalBytes() 

      to

      webView.page()->bytesReceived()

      in the slot, the numbers always are equal on the first (successful) try while bytesReceived() is smaller than totalBytes() on all failed tries.

      When changing the loadingFinished->slot connection type from DirectConnection to QueuedConnection the problem disappears and proper geometries are found on every try.

      It seems to me that the loadingFinished signal is emitted to early (before the QWebView DOM is setup properly) if QWebView can satisfy the URL load request more quickly using some cache.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            annulen Konstantin Tokarev
            silicomancer Bernhard Lindner
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes