Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get Source code of QWebEnginePage
Qt 6.11 is out! See what's new in the release blog

Get Source code of QWebEnginePage

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 1.5k Views 1 Watching
  • 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.
  • AmrCoderA Offline
    AmrCoderA Offline
    AmrCoder
    wrote on last edited by
    #1

    when I press left click on any web page in webEngineview I have the option to view the source code for the current page.
    that I want to do it programming I want to set this page source code to a QString so I can do what I want with it
    I tried both
    QWebEnginePage.toHtml() and toPlaintText but both not give me as I found in the left click view page source code from the view
    for example, i tried on facebook page toHtml give me codes and the view page source code give me a more detailed code that what I want so any help to get this code to QString
    thanks in advance

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Don't know why toHtml() and right-click-view disagree. Maybe you can use the following as a work-around. It gives the exact content of the right-click-view:

      ui->webEngineView->setUrl(QUrl("view-source:https://facebook.com"));
      // ...
      // on load finished:
      ui->webEngineView->page()->toPlainText( [this](QString const &s){ ui->plainTextEdit->setPlainText(s); } );    
      
      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved