Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. PyQt share session between two QWebView widgets
QtWS25 Last Chance

PyQt share session between two QWebView widgets

Scheduled Pinned Locked Moved Solved Qt WebKit
4 Posts 2 Posters 1.8k 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.
  • J Offline
    J Offline
    jspeirs
    wrote on last edited by
    #1

    My app has two QWebViews in it. If a user navigates to a page in one of the WebViews and logs in then I'd like for that users login session to also work in the second WebView (so they don't have to login twice). Is there a way to do that?

    I was playing around with QNetworkCookieJar and QNetworkAccessManager but didn't get anything to work.

    I may have found an answer to this but it's in c++ and I don't know how to interpret it to python:

    https://stackoverflow.com/a/9129003/377205

    K 1 Reply Last reply
    0
    • J jspeirs

      My app has two QWebViews in it. If a user navigates to a page in one of the WebViews and logs in then I'd like for that users login session to also work in the second WebView (so they don't have to login twice). Is there a way to do that?

      I was playing around with QNetworkCookieJar and QNetworkAccessManager but didn't get anything to work.

      I may have found an answer to this but it's in c++ and I don't know how to interpret it to python:

      https://stackoverflow.com/a/9129003/377205

      K Offline
      K Offline
      Konstantin Tokarev
      wrote on last edited by
      #2

      @jspeirs Code in your link deals with loading and saving cookies from/to file. If you don't need this, the only thing you should do is to set up the same QNetworkAccessManager into both QWebView objects (or same cookie jar, but this is less efficient)

      J 1 Reply Last reply
      1
      • J Offline
        J Offline
        jspeirs
        wrote on last edited by
        #3

        Ah ok I got it. I was over complicating it. Used this code to get the behavior I was looking for.

        manager = QtNetwork.QNetworkAccessManager()
        webview = QtWebKitWidgets.QWebView()  
        webpage = webview.page()        
        webpage.setNetworkAccessManager(manager)
        webview.load(QUrl(url))
        
        1 Reply Last reply
        0
        • K Konstantin Tokarev

          @jspeirs Code in your link deals with loading and saving cookies from/to file. If you don't need this, the only thing you should do is to set up the same QNetworkAccessManager into both QWebView objects (or same cookie jar, but this is less efficient)

          J Offline
          J Offline
          jspeirs
          wrote on last edited by
          #4

          @Konstantin-Tokarev thanks, you helped me simplify my approach.

          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