qt - Javascript doesn't use QWebView cookies/session -



qt - Javascript doesn't use QWebView cookies/session -

i trying develop basic browser web in order surf on specific net site using qt framework. created mywindow class inherits qwebview, in order handle opening of potential pop-ups in new browser window. in mywindow class recreated createwindow function. moreover, created qnetworkaccessmanager , qnetworkcookiejar objects within mywindow class , without recreating farther new function. thought sufficient surf on website targeting, has log-in form in homepage, while can surf on other pages of same site using info contained within server-generated cookies @ log-in. works during "normal" navigation, while error when clicking on links such as

<a class="lien_default lienperso" href="javascript:popupperso('foo.php?login=bar')">bar</a>

in case, new window prompted (i discovered javascript function simple window.open) seems cannot retrieve info cookies: current session not used , new window asks logging-in again. after logging-in in pop-up window can surf right linked page. intention of course of study utilize info of each current session access info of link. , behaviour (i.e. no sec log-in request) while surfing web page standard browsers. discovered these links not handled linkclicked signal due javascript code.

please find here under code:

main.cpp

#include <qapplication> #include "mainwindow.h" int main(int argc, char *argv[]) { qapplication a(argc, argv); mainwindow mwind; mwind.show(); homecoming a.exec(); }

mywindow.cpp

#include <qwebview> #include "mywindow.h" mywindow::mywindow (qwidget * parent):qwebview(parent) { } qwebview *mywindow::createwindow(qwebpage::webwindowtype type) { q_unused(type); qwebview *webview = new qwebview; qwebpage *newweb = new qwebpage(webview); webview->setattribute(qt::wa_deleteonclose, true); webview->setpage(newweb); homecoming webview; }

mainwindow.cpp

#include "mainwindow.h" #include "ui_mainwindow.h" #include "mywindow.h" #include <qwebview> #include <qwebframe> #include <qnetworkaccessmanager> #include <qnetworkcookiejar> mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent), ui(new ui::mainwindow) { qurl url([url of website targeting]); ui->setupui(this); qwebsettings *settings = ui->w->settings(); // w object of mywindow class promoted in design panel settings->setattribute(qwebsettings::javascriptenabled, true); settings->setattribute(qwebsettings::pluginsenabled, true); settings->setattribute(qwebsettings::autoloadimages, true); settings->setattribute(qwebsettings::javaenabled, false); settings->setattribute(qwebsettings::javascriptcanopenwindows, true); ui->w->page()->setlinkdelegationpolicy(qwebpage::delegatealllinks); // test on links qnetworkcookiejar* cookiejar = new qnetworkcookiejar(); qnetworkaccessmanager* nam = new qnetworkaccessmanager(this); nam->setcookiejar(cookiejar); ui->w->page()->setnetworkaccessmanager(nam); ui->w->load(url); ui->w->show(); net=nam; connect(ui->w,signal(linkclicked(qurl)),this,slot(openurl(qurl))); } mainwindow::~mainwindow() { delete ui; } void mainwindow::openurl(qurl url) { qwebview *n = ui->w->createwindow(qwebpage::webbrowserwindow); n->page()->setnetworkaccessmanager(net); n->load(url); n->show(); }

thank you

hicarus

the page created in mywindow::createwindow doesn't seem networkaccessmanager set cookies, seek like:

qwebpage *newweb = new qwebpage(webview); newweb->setnetworkaccessmanager(page()->networkaccessmanager());

another alternative create subclass of qwebpage logic instead of doing in multiple places, , homecoming such object createwindow.

javascript qt cookies qwebview

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -