Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

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

    QtWebEngine
    2
    3
    233
    Loading More Posts
    • 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
      mbwgh last edited by

      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 Reply Quote 0
      • eyllanesc
        eyllanesc last edited by

        @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 Reply Quote 0
        • M
          mbwgh last edited by mbwgh

          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 Reply Quote 0
          • First post
            Last post