Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QWebView check on valid load

QWebView check on valid load

Scheduled Pinned Locked Moved Qt WebKit
34 Posts 4 Posters 16.3k 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.
  • A Offline
    A Offline
    ArcNexus
    wrote on last edited by
    #6

    I have this code in my project and it works fine. It isn't exactly the same case, but....

               @ connect(ui->webLogoLaboratorio,SIGNAL(loadFinished(bool)),this, SLOT(cargaFinalizadaLogo(bool)));
    
                    QUrl  uUrl;
                    QString cUrl = "http://xxxxxx.com/documentos/image/fotos/medicamento/"+e.text().trimmed()+"_1.jpg";
                    uUrl.setUrl(cUrl);
                    ui->webLogoLaboratorio->load(uUrl);
    

    void FrmInformacionFarmaco::cargaFinalizadaLogo(bool estado)
    {

    if(ui->webLogoLaboratorio->findText("Not Found"))
        ui->webLogoLaboratorio->setVisible(false);
    else
        ui->webLogoLaboratorio->setVisible(true);
    

    }@

    this waits for completly loaded webpage. And when is completly loaded it run CargaFinalizadaLogo metod, and test if xxxx text is in qWebview. In my case if image is not in server, it return 404- not found, If this text is present I hide control, otherwise it shows image

    I think is similar at your problem. good luck

    When we are one, we win

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bagipro
      wrote on last edited by
      #7

      Yes, but i have same code.
      For example, full page:
      @<html>
      <title>Hello world<title>
      <meta>some data</meta>
      [removed]script[removed]
      <table>
      <tr>
      <td>one</td>
      <td>two</td>
      <td>three</td>
      </tr>
      </table>
      </html>@

      But sometimes i get (all times differently)
      @<html>
      <title>Hello world<title>
      <meta>some data</meta>
      [removed]script[removed]
      </html>@

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ArcNexus
        wrote on last edited by
        #8

        And if you open url in web browser like firefox it works fine all times?

        Make sure your php or asp code for ensure problem is not in your server code.

        Your example gives impresion that for some reason your server not have data to return.

        When we are one, we win

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bagipro
          wrote on last edited by
          #9

          Oh no, in browser all works correctly, it is not server's problem

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ArcNexus
            wrote on last edited by
            #10

            Maybe, if you copy here your code, we will can find where is the problem

            When we are one, we win

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MaximAlien
              wrote on last edited by
              #11

              Hi,

              You can check whether all data was loaded using @void QNetworkReply::downloadProgress ( qint64 bytesReceived, qint64 bytesTotal ) [signal]@ signal.

              Hope it helps.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                bagipro
                wrote on last edited by
                #12

                ArcNexus, I haven't server code, but i sure that is application bug.

                This is app code
                @QObject::connect(&view,SIGNAL(loadFinished(bool)),&loopLoad,SLOT(quit()));
                QObject::connect(&timer,SIGNAL(timeout()),&loopLoad,SLOT(quit()));@

                @view.load(QUrl("https://www.site.com/"));
                timer.start(SOCKS_TM);
                loopLoad.exec();
                if(!timer.isActive())
                {
                timer.stop();
                view.stop();
                }@

                MaximAlien, thanks, i will check

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  ArcNexus
                  wrote on last edited by
                  #13

                  Can you comment timer lines? and test again, maybe the timer cause an exit before the html code has completly downloaded from server?. I think it is a possible cause.

                  When we are one, we win

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    bagipro
                    wrote on last edited by
                    #14

                    No
                    @if(!timer.isActive())
                    {
                    timer.stop();
                    view.stop();
                    }@
                    It is check on timeout, if request takes longer than SOCKS_TM ms, then i do abort of an operation (i pasted not full code)

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      ThatDude
                      wrote on last edited by
                      #15

                      I see you've connected view's loadFinished signal...
                      well you better connect view.page()->mainFrame() loadFinished
                      because if a view which is a webpage contains more frames/iframes you could possible receive loadFinished from each one of the frames
                      I guess you catch only the first loadFinished.

                      There is no way to know when page finished loading...
                      the best approach perhaps is to wait for let's say 3-5 seconds without data transfer and its not 100% correct. loadFinished actually tells us that HTML i.e. the code of that page (frame) just loaded nothing more. After the HTML source code of the page loaded then browser (or QWebView in our case) starts interpreting and running that code so... in a few (milli)seconds without transfer some JavaScript could start loading something, or some json or whatever so if a page has javascript that constantly loading/refreshing data (e.g. stock exchange data) you will receive loadFinished only once (per i/frame) yet JavaScript or json could constantly refresh it in the background - so when should we consider such a page fully loaded?!

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        bagipro
                        wrote on last edited by
                        #16

                        ThatDude, likely! But i edited the code, but nothing has changed :( Often the page doesn't load until the end.

                        @QWebFrame* frame = view.page()->mainFrame();@

                        @QObject::connect(frame,SIGNAL(urlChanged(QUrl)),&loopUrlChanged,SLOT(quit()));
                        QObject::connect(frame,SIGNAL(loadFinished(bool)),&loopLoad,SLOT(quit()));
                        QObject::connect(&timer,SIGNAL(timeout()),&loopUrlChanged,SLOT(quit()));
                        QObject::connect(&timer,SIGNAL(timeout()),&loopLoad,SLOT(quit()));@

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          bagipro
                          wrote on last edited by
                          #17

                          I'm sure that signal it is general trouble, something work wrong .
                          For example, @SIGNAL(loadFinished(bool))@ triggered, but url is NOT CHANGED

                          I use evaluateJavaScript method
                          @frame->evaluateJavaScript(QString("document.getElementById("login_email").value = "%1"").arg(email));
                          frame->evaluateJavaScript(QString("document.getElementById("login_password").value = "%1"").arg(pass));
                          frame->evaluateJavaScript("document.login_form.submit()");@

                          And after
                          @timer.start(SOCKS_TM);
                          loopUrlChanged.exec();//отправка формы
                          if(!timer.isActive())
                          {
                          timer.stop();
                          view.stop();
                          break;
                          }

                                  timer.start(SOCKS_TM);
                                  loopLoad.exec&#40;&#41;;
                                  if(!timer.isActive(&#41;&#41;
                                  {
                                      timer.stop(&#41;;
                                      view.stop(&#41;;
                                      break;
                                  }@
                          

                          By the end, the page is the same

                          What i doing wrong?

                          1 Reply Last reply
                          0
                          • T Offline
                            T Offline
                            ThatDude
                            wrote on last edited by
                            #18

                            It will be eaiser to debug if you use QWebElement instead
                            @ void Form::submitInfo()
                            {
                            QWebFrame *frame = ui->webView->page()->mainFrame();

                                QWebElement firstName = frame->findFirstElement("#firstname");
                             
                                firstName.setAttribute("value","some text");
                             
                            }
                            

                            @
                            OR
                            @ QWebFrame *frame = ui->webView->page()->mainFrame();

                                QWebElement firstName = frame->findFirstElement("#firstname");
                                firstName.evaluateJavaScript("this.value='some text' ").
                            

                            @
                            You could even do this
                            @elem.setFocus()
                            elem.evaluateJavaScript("this.click()")
                            @

                            1 Reply Last reply
                            0
                            • B Offline
                              B Offline
                              bagipro
                              wrote on last edited by
                              #19

                              Yes, but trouble is not in evaluateJavaScript. I would like to say that it sometimes does not work, not all time. And the main problem in the wrong load. It does not load to the end

                              1 Reply Last reply
                              0
                              • T Offline
                                T Offline
                                ThatDude
                                wrote on last edited by
                                #20

                                Well,
                                perhaps you should wait a bit longer... if you use QWebElement you could wait until that element shows on page.

                                Are you sure that data really hits your browser - you could use some tools to check that - Fiddler (web debugging proxy) or Wireshark (network protocol analyzer)

                                1 Reply Last reply
                                0
                                • B Offline
                                  B Offline
                                  bagipro
                                  wrote on last edited by
                                  #21

                                  Ok, i will check (fiddler doesn't fix it because i use proxy, i need to use wireshark or windows network monitor).

                                  But see, there is all correctly?
                                  @QObject::connect(frame,SIGNAL(urlChanged(QUrl)),&loopUrlChanged,SLOT(quit()));
                                  QObject::connect(frame,SIGNAL(loadFinished(bool)),&loopLoad,SLOT(quit()));
                                  QObject::connect(&timer,SIGNAL(timeout()),&loopUrlChanged,SLOT(quit()));
                                  QObject::connect(&timer,SIGNAL(timeout()),&loopLoad,SLOT(quit()));@

                                  1 Reply Last reply
                                  0
                                  • B Offline
                                    B Offline
                                    bagipro
                                    wrote on last edited by
                                    #22

                                    [quote author="bagipro" date="1374304254"]Ok, i will check (fiddler doesn't fix it because i use proxy, i need to use wireshark or windows network monitor).[/quote]

                                    I remembered! My site using ssl (https), i can't fix it :(

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      ArcNexus
                                      wrote on last edited by
                                      #23

                                      had to be server :p

                                      some times yes, other times no..... mmmm that sounds at server problems....

                                      When we are one, we win

                                      1 Reply Last reply
                                      0
                                      • B Offline
                                        B Offline
                                        bagipro
                                        wrote on last edited by
                                        #24

                                        [quote author="ArcNexus" date="1374324206"] had to be server :p
                                        some times yes, other times no..... mmmm that sounds at server problems....
                                        [/quote]
                                        Heh, I checked yandex.ru (normal size from 160 to 175 KB) using different proxy for each load and we see:
                                        !http://clip2net.com/clip/m0/1374349499-clip-30kb.png(1)!
                                        !http://clip2net.com/clip/m0/1374349970-clip-51kb.png(1)!

                                        1 Reply Last reply
                                        0
                                        • T Offline
                                          T Offline
                                          ThatDude
                                          wrote on last edited by
                                          #25

                                          As I said...

                                          1. you do not wait long enough
                                          2. there is no way of knowing when the page is fully loaded
                                          3. HTTPS - Webkit has some troubles with https esp. on windows. I never had any trouble with that on linux
                                            Does you site use self-signed certificate? In that case you might want to add to to the list of know i.e. trusted authorities

                                          Can you show us same yandex.ru requests/responses after you change your timer to wait e.g. 3 min per each request i.e. do not rely on loadFInished ...
                                          Even ui->webView->page()->mainFrame() could fire multiple loadFinished signal if it has (static or dynamically created) internal frames or iframes
                                          so sitting and waiting only for the very first loadFinished won't help you much
                                          you might want to investigate different approaches using a timer:

                                          1. wait for say 3 sec. without any other loadFinished for mainFrame
                                          2. wait for say 3 sec. without any more data coming for that page/view
                                            QWebPage::totalBytes
                                            QWebPage::bytesReceived () const
                                          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