×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    228

    Question set an Http request and add the response to a list

    Hi everyone,

    i am newbie here developing for meego device N9 and for using qml
    what i am trying to do is to send an http request to the server and get the response then display it into a list .
    Can anyone help about what should i do accomplish that in qml?
    Thank you

  2. #2
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: set an Http request and add the response to a list

    Hi,
    There are 2 ways:
    1. Best - Use XMLHttpRequest inside a javascript as shown in the snippet below.
    2. More complicated -Use C++ and bind your C++ class to QML.

    import QtQuick 1.0

    Item {
    Component.onCompleted: {
    var req = new XMLHttpRequest();
    req.onreadystatechange = function() {
    console.log("readyState: " + req.readyState);

    if (req.readyState == XMLHttpRequest.DONE) { // 4 instead of 'XMLHttpRequest.DONE' works here too
    console.log("Request complete");

    if (req.status == 200) {
    console.log("Status code: 200");
    console.log(req.responseText.slice(0, 50) + "...")
    }
    }
    }

    req.open("GET", "http://developer.nokia.com/");
    req.send();
    }
    }

  3. #3
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    228

    Re: set an Http request and add the response to a list

    Quote Originally Posted by gnuton View Post
    Hi,
    There are 2 ways:
    1. Best - Use XMLHttpRequest inside a javascript as shown in the snippet below.
    2. More complicated -Use C++ and bind your C++ class to QML.

    hi , thx for your reply
    i tried to bind my C++ class into my qml , but i am facing the problem that when i add the bearer mobility to my pro file..it is always giving me cannot find -lQtBearer
    so i guess maybe it is easier to use ur method..i have implemented your method and a hit was sent to the server successfully .
    i have posted some data to the server by replacing the get line and send by the following:
    req.open("POST", "http://....",true);
    req.send("1]test");
    can u please help me how can i get the server response req.responseText(list of names) and insert them into a list ?
    Thank you again for your help
    Last edited by Rondo23; 2011-10-26 at 13:05.

  4. #4
    Super Contributor
    Join Date
    Mar 2009
    Posts
    1,024

    Re: set an Http request and add the response to a list

    Hi
    Bearer is part of Qt 4.7 then you don't need -lQtBearer at all.

    After send you can use synchronous API
    req.send();
    var serverResponse = req.responseText;
    alert(serverResponse);
    or the asynchronous one:
    function onResponse() {
    if (xhReq.readyState != 4) { return; }
    var serverResponse = xhReq.responseText;
    ...
    }
    ...
    req.onreadystatechange = onResponse;
    req.send(null);
    Once you have resonseText then you can create an array of strings and use it as model or
    you could parse responseText and insert items in a your own ListModel.
    to insert item in the listModel you can use myListModel.append(something).

    http://doc.qt.nokia.com/4.7-snapshot/qml-listmodel.html

  5. #5
    Regular Contributor
    Join Date
    Dec 2010
    Posts
    228

    Re: set an Http request and add the response to a list

    Thank you gnuton a lot for your help

Similar Threads

  1. N70 request response using http
    By satyarajasekhar in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2008-08-07, 10:31
  2. Abt HTTP request/response in RDA service
    By girdhar in forum Mobile Java General
    Replies: 4
    Last Post: 2007-05-09, 05:06
  3. Http request/response problem
    By mrekha01 in forum Symbian
    Replies: 3
    Last Post: 2007-02-01, 17:09
  4. Http request/response problem
    By mrekha01 in forum Symbian
    Replies: 4
    Last Post: 2007-02-01, 09:51

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×