[Qt-qml] Authentication from a QML application

Girish Ramakrishnan girish at forwardbias.in
Tue Oct 18 20:04:35 CEST 2011


Hi,

On Tue, Oct 18, 2011 at 11:13 PM, Juha Turunen <turunen at iki.fi> wrote:
> On Tue, Oct 18, 2011 at 6:13 PM, Johan Paul <johan.paul at gmail.com> wrote:
>> HTTP Auth is your traditional browser popup to log in to sites with.
>> AFAIK there is no way to do this in QML right now. But I would also like
>> to be proven wrong (or hear it's available in QtQuick2).
>
> QML's XHR implements the good old W3C API which has support for HTTP
> authentication. Just pass the username and password as parameters in
> the call to send().
>
> import QtQuick 1.0
>
> Item
> {
>    width: 400
>    height: 400
>
>    MouseArea {
>        anchors.fill: parent
>        onClicked: {
>             var doc = new XMLHttpRequest();
>             doc.onreadystatechange = function() {
>                 if (doc.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
>                     console.log("Headers:");
>                     console.log(doc.getAllResponseHeaders());
>
>                 } else if (doc.readyState == XMLHttpRequest.DONE) {
>                     console.log("Response:");
>                     console.log(doc.responseText);
>                 }
>             }
>
>             doc.open("GET",
> "http://koivi.com/php-http-auth/protect.php", true, "tester",
> "testing");
>             doc.send();
>        }
>    }
> }

I think the OP was asking about displaying a webpage that requires
HTTP auth. AFAIK, there's no way to do that without having to create
your own WebView. Since the WebView does not allow customizing the
QNAM, pretty much all features related to QNAM are not available.

These are times when I wish the C++ item code is public :-).

Girish


More information about the Qt-qml mailing list