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
Forum Updated to NodeBB v4.3 + New Features

PyQt share session between two QWebView widgets

Scheduled Pinned Locked Moved Solved Qt WebKit
4 Posts 2 Posters 1.9k 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.
  • J Offline
    J Offline
    jspeirs
    wrote on 23 Feb 2018, 23:48 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 25 Feb 2018, 17:23
    0
    • J jspeirs
      23 Feb 2018, 23:48

      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 25 Feb 2018, 17:23 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 27 Feb 2018, 17:42
      1
      • J Offline
        J Offline
        jspeirs
        wrote on 27 Feb 2018, 17:32 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
          25 Feb 2018, 17:23

          @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 27 Feb 2018, 17:42 last edited by
          #4

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

          1 Reply Last reply
          0

          1/4

          23 Feb 2018, 23:48

          • Login

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