I have a QWebView, and it loads a certain page, the user logs in and goes about his business. This all works fine.
What I would like to do is have a second frame/pae open, that uses the logged in users session and all that jazz to load a reports page that it will render to an image file for display on a little USB screen.
Right now, I accomplish this with a completely different webView, which can't access protected pages, which is a bit of a security risk.
Here is some pseudo code for what I am thinking of:
webView->mainFrame->loadNormalUrl
secretFrame = webView->createSecretFrame
secretFrame->useSessionOf(webView->mainFrame)
secretFrame->loadReportUrl
secretFrame->doStuffThatAlreadyWorks
Any help, pointers, links would be super helpful! Thanks :)
Well,
This question didn't receive and answer, so I pattered off to the qtwebkit mailing list, and they were very helpful.
The essential thing is to subclass QNetworkCookieJar, the most important method being the loading from disk, which you call in your constructor.
QList<QNetworkCookie> cookies;
if (m_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream in(&m_file);
QString txt = in.readAll();
QStringList lines = txt.split("\n");
foreach (QString c, lines) {
cookies.append(QNetworkCookie::parseCookies(c.toUtf8()));
}
m_file.close();
}
setAllCookies(cookies);
Of Course, you'll also need a writing function, like so:
QTextStream out(&m_file);
foreach (const QByteArray &cookie, m_rawCookies)
out << cookie + "\n";
m_file.close();
And your raw cookies like so:
QList<QNetworkCookie> cookies = allCookies();
m_rawCookies.clear();
foreach (const QNetworkCookie &cookie, cookies) {
m_rawCookies.append(cookie.toRawForm());
}
If you download the webkit source, you can take a look at the testbrowser code for a more complete example.