Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. How do you share data between QWebEngineView and the C++ side?
QtWS25 Last Chance

How do you share data between QWebEngineView and the C++ side?

Scheduled Pinned Locked Moved Solved QtWebEngine
3 Posts 2 Posters 628 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.
  • M Offline
    M Offline
    mbwgh
    wrote on last edited by
    #1

    Hello,

    I would like to implement a small web crawler in C++, using Qt. What I would like to be able to do is have a QWebEngineView navigate to some url, and then extract some links using a CSS selector. Then proceed to process these links, if possible using several QWebEngineViews concurrently.

    However, I am currently stuck on how to get any data out and to the surrounding C++ process. I saw that you can use the LocalStorage API with Qt Quick, but I did not intend to switch to QML.
    So my other idea was to use QWebEnginePage::runJavaScript to assign some value to document.cookie and intercept that using a signal handler for QWebEngineCookieStore::cookieAdded.

    Unfortunately, that does not seem to work either since now I am getting
    "Uncaught SecurityError: Failed to set the 'cookie' property on 'Document': Access is denied for this document."

    Is my approach a fool's errand? Or what would be some hints on how to proceed from here?

    1 Reply Last reply
    0
    • eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @mbwgh Use Qt WebChannel, by example: https://stackoverflow.com/questions/61764733/capture-a-javascript-event-in-qtwebengine/61765653#61765653

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mbwgh
        wrote on last edited by mbwgh
        #3

        Thanks, I started looking into this yesterday as well, but the usage of websockets added some more complexity. So this example is really helpful!

        Since this seems to be the correct (or at the very least more principled) approach to my problem, I will mark this thread as solved.

        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