Take a look at this simplest project: https://www.dropbox.com/s/ctdcgrk0eqgq3a3/webview_test.tar.gz
When you start the application, you see a white window. Click on this window and you will see a browser in which Twitter is open. Click on the white window again and the browser will be closed, and its QQuickView will be destroyed.
So log in to Twitter. Then destroy the browser by clicking again on the main window, and then create it again by clicking again. You will see that you are still logged in. But I need the browser to open every time with the user logged out (even if he checked the "Remember me" box). How to do it? How to destroy all saved data and return the browser to its initial state? Preferably, without deleting it each time.
Here are the main parts of this project:
main.cpp
#include <QApplication> #include <QQuickView> #include "container.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Container c; c.start(); return a.exec(); } container.cpp
#include "container.h" #include <QDebug> #include <QQuickItem> #include <QQmlContext> Container::Container(QObject *parent) : QObject(parent) { mainFile = new QQuickView(); browserExists = false; } Container::~Container() { delete mainFile; } void Container::start() { mainFile->setSource(QUrl("qrc:/main.qml")); connect(mainFile->rootObject(), SIGNAL(click()), this, SLOT(mainFileClicked())); mainFile->show(); } void Container::mainFileClicked() { if(!browserExists) { browser = new QQuickView(); browser->setSource(QUrl("qrc:/browser.qml")); browser->rootContext()->setContextProperty("address", "http://twitter.com"); browser->show(); browserExists = true; } else { browser->hide(); delete browser; browserExists = false; } } main.qml
import QtQuick 2.0 Rectangle { width: 320 height: 240 signal click(); MouseArea { anchors.fill: parent onClicked: { click() } } } browser.qml
import QtQuick 2.0 import QtWebKit 3.0 import QtWebKit.experimental 1.0 Item { width: 640 height: 480 signal closeWindow(); WebView { anchors.fill: parent url: address experimental.preferences.privateBrowsingEnabled: true } }