PyQt share session between two QWebView widgets
-
wrote on 23 Feb 2018, 23:48 last edited by
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:
-
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:
wrote on 25 Feb 2018, 17:23 last edited by@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 bothQWebView
objects (or same cookie jar, but this is less efficient) -
wrote on 27 Feb 2018, 17:32 last edited by
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))
-
@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 bothQWebView
objects (or same cookie jar, but this is less efficient)wrote on 27 Feb 2018, 17:42 last edited by@Konstantin-Tokarev thanks, you helped me simplify my approach.
1/4