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

QML webview delete cookies

Scheduled Pinned Locked Moved Qt WebKit
3 Posts 2 Posters 2.3k Views
  • 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.
  • T Offline
    T Offline
    twisted
    wrote on 1 Dec 2016, 09:27 last edited by
    #1

    I'm using a basic webview in QML to login to a website, however I need to be able to clear cookies in order to log the user out but I can't find a way to do this using QT 5.7 and the QML webview.

    All I can find are references to older versions of the webview that suggest using either the experimental privatebrowsing flag which doesn't appear to be part of the experimental library anymore or using a cookiejar which also appears to no longer be used by webview.
    I even resorted to trying to run custom javascript using the webview runJavaScript function but it just complained that document wasn't defined.

    If someone could point me in the right direction it'd be much appreciated.

    K 1 Reply Last reply 1 Dec 2016, 10:38
    0
    • T twisted
      1 Dec 2016, 09:27

      I'm using a basic webview in QML to login to a website, however I need to be able to clear cookies in order to log the user out but I can't find a way to do this using QT 5.7 and the QML webview.

      All I can find are references to older versions of the webview that suggest using either the experimental privatebrowsing flag which doesn't appear to be part of the experimental library anymore or using a cookiejar which also appears to no longer be used by webview.
      I even resorted to trying to run custom javascript using the webview runJavaScript function but it just complained that document wasn't defined.

      If someone could point me in the right direction it'd be much appreciated.

      K Offline
      K Offline
      Konstantin Tokarev
      wrote on 1 Dec 2016, 10:38 last edited by
      #2

      @twisted Unfortunately clean way to do this was not implemented yet. Seems like the only ways is to find and remove cookies.db files, that should be located in ${QStandardPaths::DataLocation}/.QtWebKit (e.g. actual path can be something like ~/.local/share/QtProject/QtMiniBrowser/.QtWebKit/cookies.db)

      1 Reply Last reply
      0
      • T Offline
        T Offline
        twisted
        wrote on 1 Dec 2016, 11:20 last edited by
        #3

        Thanks for the tip, I'm running on Windows at the moment and found the cookies stored under {QStandardPaths::DataLocation}/QtWebEngine.

        For anyone else looking at this the following code should clear your cookies

            //Delete cookies
            QStringList paths = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
        
            for (int i = 0; i < paths.size(); ++i)
            {
                QDir dir(paths.at(i) + "/QtWebEngine");
                if (dir.isReadable())
                    dir.removeRecursively();
            }
        
        1 Reply Last reply
        0

        1/3

        1 Dec 2016, 09:27

        • Login

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