LINUX.ORG.RU

QtWebKit: QWebFrame::loadFinished and JavaScript execution


0

1

Right now I am using this code:

void ObjName::func1() {
  connect(_webPage.mainFrame(), SIGNAL(loadFinished(bool)), this, SLOT(finished()));
}

void ObjName::finished() {
  if (_state == 1) {
    _state++;
    _webPage.mainFrame()->findFirstElement("[name=\"submit\"]").evaluateJavaScript("this.click()");
  } else {
    // ...
  }
}

My goal is to submit form only after it is fully loaded and all JavaScript in it is properly executed (page contains JavaScript code that changes input values). However, the documentation of QWebFrame::loadFinished(bool) SIGNAL doesn't say anything regarding JavaScript execution. I am worried if I am just lucky and in this case JavaScript executes fast enough after page is loaded. Is it possible that my code will break with more complex JavaScript? Should I use another SIGNAL? I couldn't find any other appropriate SIGNAL in QtWebKit documentation.

Accordingly to Qt documentation

This signal is emitted when the page finishes loading content. This signal is independant of script execution or page rendering. ok will indicate whether the load was successful or any error occurred.

Basically, this signal will be emitted when html is loaded, before scripts execution and page render. So yes, in theory, you may experience some kind of race conditions here.

As for other signals to fulfill your needs, I'm afraid they just don't exist. You can use some hacks with delayed script execution, but you can never be sure.

Dantix ★★
()
Ответ на: комментарий от Dantix

My version of documentation doesn't contain sentence about script execution for QWebFrame::loadFinished(bool). It seems you cited QWebPage::loadFinished(bool). Not sure if there is any difference or they just forgot to mention for QWebFrame::loadFinished(bool).

Actually I am beginning to understand why such signal doesn't exist - as JavaScript is highly asynchronous language it would involve complex analyzes of all callback functions.

May be QWebFrame::initialLayoutCompleted() is more appropriate SIGNAL to use here?

driowria
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.