[Interest] Is there a QML way for doing web requests? Just for data, not for rendering.

Mark Gaiser markg85 at gmail.com
Thu Dec 28 16:15:45 CET 2017


On Thu, Dec 28, 2017 at 2:25 PM, Shawn Rutledge <Shawn.Rutledge at qt.io>
wrote:

> On 22 Dec 2017, at 23:19, Mark Gaiser <markg85 at gmail.com> wrote:
> >
> > Hi,
> >
> > You know those fancy REST api's out there.
> > How does one use them in QML?
> >
> > For websockets the answer is simple: QML WebSocket.
> > But i didn't find a way to just do a web request to some url and get
> it's data, at least not a way that seems "QMLified".
> >
> > Sure, javascript can be used with it's XMLHttpRequest which will work
> just fine, but using it seems so.. not QML like. So is there a QML way to
> do such things?
>
> Not AFAIK, except for anything (like Image) which has a source URL.
>
> Why don’t you like XMLHttpRequest?  How would you want the QML API to look
> then? Do you expect to do some data processing in JS after you fetch the
> data, or just looking for a way to pass the data to some C++ code?  If the
> latter, why not do the loading in C++ too?
>
> (at least some of those are rhetorical questions… ;-)
>
>
Well, in my ideal situation the web request fills a model which is then
hooked into a view.
An hypothetical API like:

WebRequestModel {
  id: webRequest
  url: "https://some/webservice/url"
  parseType: WebRequestModel.JSON
}

ListView {
  model: webRequest
  .. and some delegate stuff ..
}

Done :)
That would look really clean to me and be very powerful for QML. I'm
slightly surprised that QML doesn't have something like this yet.

A little explanation for the hypothetical "WebRequestModel". As i wrote it
above it should have multiple ways to parse it's data. JSON in this case,
but also XML and YAML at the very least.
The QML -> C++ passing would just be the url from the QML side to the C++
QAIM implementation. There the JSON (and other types) would be parsed.
This structure would only work with simple data outputs from web services.
Not if there is cruft around the data that you'd need to filter out first.
You could add a hypothetical property to the hypothetical WebRequestModel
called "path" or "xpath" which would define the part of the data to use for
the model.

As for not liking XMLHttpRequest. It works.... I just don't like it's API.
It looks very verbose and very specific for website backends. Not really
fitting (api wise) for QML.
Did i answer all your questions? :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20171228/f5e3bc3b/attachment.html>


More information about the Interest mailing list