Results 1 to 4 of 4

Thread: Cookie problem with QtWebkit

  1. #1
    Join Date
    Jun 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Question Cookie problem with QtWebkit

    Hi!

    I would like to use QtWebkit to log in to a site, and then download some data.Unfortunately if I load the page with the webkit( QWebView::load()) I cant log in, and the site claims that I don't have cookies enabled, even though I have created a QNetworkCookieJar, and set it to the QNetworkAccessManager of the page.

    here's a piece of my code:

    Qt Code:
    1. Downloader::Downloader(QWidget *parent)
    2. : QMainWindow(parent), ui(new Ui::DownloaderClass),state(First)
    3. {
    4. manager=new QNetworkAccessManager();
    5. jar=new MyCookieJar();
    6. manager->setCookieJar(jar);
    7. view=new QWebView();
    8. view->setMinimumSize(800,600);
    9. connect(view,SIGNAL(loadFinished(bool)),this,SLOT(loaded(bool)));
    10. view->load(QUrl("http://portfolio.hu/users/elofizetes_info.php?t=koteslista"));
    11. QWebSettings::globalSettings()->setOfflineStoragePath("C:\\Users\\Zsolt\\Desktop\\");
    12. }
    To copy to clipboard, switch view to plain text mode 

    the MyCookieJar is a subclass of QNetworkCookieJar class and only implements a getCookies() function, returning all the coookies stored ( the QNetworkCookieJar::allCookies() function is protected). In the loaded(bool) function i print all the cookies stored.
    I only got a "cookie = 1;", and normally i would have a lot more( checked with wireshark).
    And since i can only set the QNetworkAccessManager to a page, i do that every time the view loads one.

    I tried to manually copy the protocol, and save the cookies, using QHttp, and the headers, but apparently some javascript code generates an ID to be sent to the site when logging in.

    Please help me log in(and stay logged in) either with using QtWebkit, or with simple QHttp classes.

    Any reply would be appreciated.

  2. #2
    Join Date
    Jun 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cookie problem with QtWebkit

    Solved it.
    I found the javascript code generating the cookie, copied it, and then I had to set some values in the cookie header(host,origin,referer,user-agent,...)

  3. #3
    Join Date
    Mar 2010
    Location
    The Netherlands
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cookie problem with QtWebkit

    Hi iam also working on saving cookies to disk. I see you have already solved your problem however, could you show me how your MyCookieJar class works?

    Thanks in advance.

  4. #4
    Join Date
    Feb 2008
    Posts
    60
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cookie problem with QtWebkit

    Hi all,

    I am loading a URL into the WebView (using load () method), this URL having UserLogin with Remember me option. Can any one help me how to remember UserLogin by enabling Cookie.

    Regards,
    Jay.

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  2. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  3. QtWebKit Compilation problem
    By PiXeL16 in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2008, 00:18
  4. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.