Looks. Here is the simplest code: https://www.dropbox.com/s/ctdcgrk0eqgq3a3/webview_test.tar.gz [dropbox.com]
When you start this app you will see white window. Click on window and you will see browser with Twitter. Click again and browser will be hide and destroyed.
So, please login to Twitter, than destroy browser by clicking first window and then create it again by clicking on first window. You will see that you left signed in. But I need that browser every time opens without signed user (even if user checked “Remember me” checkbox). How to do this? How to reset browser to the initial state?
Here is main parts of 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
}
}
↧