QML webview delete cookies



  • 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.



  • @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)



  • 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();
        }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.