Results 1 to 8 of 8

Thread: Is QWebEnginePage::setHtml() synchronous or Asynchronous?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Re: Is QWebEnginePage::setHtml() synchronous or Asynchronous?

    The line of code below disables the JavaScript that comes with the page but that unfortunately means I cannot run my own javascript on the same page.
    Qt Code:
    1. page_1->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Is QWebEnginePage::setHtml() synchronous or Asynchronous?

    Are you sure the table is even there if you disable the script?
    I.e. isn't jQuery creating it?

    Maybe there is some form of script event in the web domain that you can use to trigger you script.

    Cheers,
    _

  3. #3
    Join Date
    Jul 2012
    Posts
    201
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Re: Is QWebEnginePage::setHtml() synchronous or Asynchronous?

    Quote Originally Posted by anda_skoa View Post
    Are you sure the table is even there if you disable the script?
    I.e. isn't jQuery creating it?

    _
    Because I am using QNAM to get the HTML, I get all the table data and all the page scripts. When I disable the scripts, the table is still there in pure html format but because the scripts are disabled, I am unable to run my own script. If I enable the scripts, something in JQuery interferes with my own script hence I cannot retrieve the data.

    The url below is the site I am trying to get the data from (i.e. the data inside the table).
    http://web1.capetown.gov.za/web1/TenderPortal/Tender/
    I've been exploring a different approach where I try to strip the HTML of all in-page scripts (i.e. using regular expressions) before I set the HTML to the QWebEnginePage. I am still working on getting the correct regular expression though, (I.e. one that is going to match everything in-between script tags and then using QString::remove() I will remove the scripts from the HTML). But I am still struggling to get the right Regular Expression. See code below.
    Qt Code:
    1. QString html = (QString)tenderPage_reply->readAll();
    2. QString temp_html = html.remove(QRegExp("\\b<script.*</script>\b"));
    3.  
    4. qDebug() << temp_html <<endl;
    5.  
    6. QFile linksFile(QDir::currentPath().append("/Include/Program_Files/tenderMainPage2.txt"));
    7.  
    8. if(!linksFile.open(QFile::WriteOnly | QFile::Text))
    9. {
    10. QMessageBox msgBox_2;
    11. msgBox_2.setText("Tender Main File did not open...");
    12. msgBox_2.exec();
    13. return;
    14. }
    15.  
    16.  
    17. QTextStream out(&linksFile);
    18. out << temp_html <<endl;
    19.  
    20. page_1 = new QWebEnginePage(this);
    21. //page_1->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
    22.  
    23. page_1->setHtml(temp_html);
    24.  
    25. QWebEngineView *view_1 = new QWebEngineView();
    26.  
    27. view_1->setPage(page_1);
    28. view_1->show();
    29.  
    30. QObject::connect(page_1, &QWebEnginePage::loadFinished, [&](){page_1->runJavaScript("document.getElementById(\"rfqsTable\").innerHTML;"
    31. ,QWebEngineScript::MainWorld, [&](const QVariant &data){
    32. qDebug() << data.toString() <<endl;
    33. });});
    34. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Is QWebEnginePage::setHtml() synchronous or Asynchronous?

    If the content you are passing at setHtml does already contain all the data, one thing you could try is to just replace all "http/https" occurences with an URL scheme that the web engine simply can't load.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    ayanda83 (16th January 2017)

Similar Threads

  1. Replies: 5
    Last Post: 26th October 2016, 15:56
  2. Replies: 4
    Last Post: 2nd May 2015, 13:09
  3. Replies: 2
    Last Post: 16th September 2014, 17:56
  4. QGraphicsTextItem - setHTML()
    By Claymore in forum Qt Programming
    Replies: 7
    Last Post: 17th September 2009, 10:34
  5. Asynchronous server msg vs synchronous functions
    By nouknouk in forum Qt Programming
    Replies: 9
    Last Post: 2nd February 2006, 18:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.