Nominate our 2022 Qt Champions!

Saving login and password with WebView on Android

  • Re: Saving login and password with WebView on Android

    You can test with minibrowser example. In my case, if use the example on my PC, login and password are saved. But not in my Android Device. Here, a simple code for example :

    #include <QtCore/QUrl>
    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    #include <QtWebView/QtWebView>
    int main(int argc, char *argv[])
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
        if (engine.rootObjects().isEmpty())
            return -1;
        return app.exec();
    import QtQuick 2.2
    import QtQuick.Controls 1.1
    import QtWebView 1.0
    import QtQuick.Layouts 1.1
    import QtQuick.Controls.Styles 1.2
    ApplicationWindow {
        property bool showProgress: webView.loading
                                    && Qt.platform.os !== "ios"
                                    && Qt.platform.os !== "winphone"
                                    && Qt.platform.os !== "winrt"
        visible: true
        width: 800
        height: 600
        title: webView.title
        Component.onCompleted: console.log(initialUrl)
        statusBar: StatusBar {
            id: statusBar
            visible: showProgress
            RowLayout {
                anchors.fill: parent
                Label { text: webView.loadProgress == 100 ? qsTr("Done") : qsTr("Loading: ") + webView.loadProgress + "%" }
        WebView {
            id: webView
            anchors.fill: parent
            url: Qt.resolvedUrl("")
    //.*pro file
    #TEMPLATE = app
    #TARGET = minibrowser
    QT += qml quick webview
    SOURCES += main.cpp
    RESOURCES += qml.qrc
    #INSTALLS += target

    Thank you for your help

  • Moderators

    @CharlieG Sorry but I dont understand what do you mean by "save" here ?

  • If you compile this code on PC and use the program, your login and password (google account for example) are saved ==> if you close the application and if you return, you are logged automaticly.

    This features doesn't work on Android device.

  • Moderators

    @CharlieG The QML WebView actually loads the native web component where it is available as said here.
    In case of android it is available as WebView.
    I think the problem is because android WebView itself doesnot allow it. As per its docs here:

    This method was deprecated in API level 18.
    Saving passwords in WebView will not be supported in future versions.

    I'm not sure if this is the exact problem.

  • @p3c0
    Thank you for your help.

    It's a pity ... I do not see how to get out of me once?
    Could there be a way to force the storage in a personal file?
    Fill out the form automatically? I tried this track but I have not managed to get a decent result ...

  • Moderators

    @CharlieG Sorry I too dont know. You can try asking it on Qt Interest Mailing List.

  • @p3c0

    I finally opted for the use of Setting (Qt.labs.settings) for storing identifiers. I then use the method void runJavaScript (string script, ranging callback) WebView and so a bit of JavaScript (document.getElementById ...) to inject what is right where it should, which can be quite painful when target lack some "standard" items (id, name, ...).

    Thank you for you help.

    Bye Bye


  • Moderators

    @CharlieG Ok. Lets hope they wont change the id in future :)

  • @p3c0 Oh yes .... I hope ;)

Log in to reply