[Development] RFC: unified data model API in QtCore => thin wrapper proposal

Arnaud Clère arnaud.clere at minmaxmedical.com
Mon Jun 18 18:35:43 CEST 2018


> From: Dmitry Volosnykh <dmitry.volosnykh at gmail.com>
> Sent: lundi 18 juin 2018 13:40
>
> FYI, there's QTBUG-29095 and QTBUG-25723 that feel like somewhat related to the problem under discussion.

I guess QTBUG-25723 is the kind of problem that Thiago solved for QCborValue

For the use case described in QTBUG-29095, I think my QBind proposal could be used instead of QJsonDocument. For instance, it can iterate over a possibly infinite JSON sequence, binding one item at a time to an appropriate in-memory data structure. So you would have to worry about accidental detaches and could use the in-memory data structure to filter or modify each item.

  MyItem myItem;
  auto i = QJsonReader(&file).begin().sequence().item();
  while (i) {
    i = i.bind(myItem);
    // do whatever you want to myItem
  }

> On Mon, Jun 18, 2018 at 2:33 PM Jason H <jhihn at gmx.com> wrote:
> +1 this.
> I'd prefer Arne's over the bind below. I do want value updates to be emitted so that we only have to change the data to keep dependent structures updated. I've suggested having some kind of xpath watcher facility...
> Having done some web UIs powered by a Ajax, (and qt will undoubtedly power some web backends) you need a facility to keep 2 trees in sync - the server data and the web UI model.  However it should be the same for QML or widget UIs... And in my dream world, a proper QML web UI. But no matter how it works, you need to be able to broadcast minimal data changes to the tree to listeners (clients).

Not sure I understand you correctly. If you miss a generic data structure with in-place editing, QCborValue or QJsonValue (sharing the same backend) may be a candidate, as are QVariant* or your own classes. QBind is not a data structure but a kind of generic iterator for data structures.

However, since QBind can traverse any data structure in a generic way, it can be used to serialize/deserialize you own specific data structures without having to first convert them to a generic data structure such as QCborValue. Converting to QCborValue would only be required to use specific Cbor features such as tags.

> > Sent: Friday, June 15, 2018 at 3:46 PM
> > From: "Tor Arne Vestbø" <Tor.arne.Vestbo at qt.io>
> >
> > Not commenting on this API, but I’d like to note that the API I brought up as “missing” from my use-case was a more “light weight” in-place edit API, where the user does not have to define bindings to data structures like above. Similar to e.g. python:

I guess the same answer as above applies.

BTW, I have committed a QBind POC on our gitlab to explain what I am talking about:
https://gricad-gitlab.univ-grenoble-alpes.fr/modmed/modmedLog/tree/f6b257d806ee50db2c5c86d90757b54ec898391b/tests/QBind

Again, this POC does not provide any in-memory data structure, it just demonstrates
how to traverse data structures in a way that is generic enough to be serialized
in different ways.

The POC is voluntarily "condensed" in a single main.cpp file + an alternate QCborWriter.hpp implementation.

The QJsonWriter now demonstrates same or better performance than hand-written serialization using QDebug, and QCborWriter is 2 to 3 times more efficient than QDebug. As opposed to QDebug, it guarantees well-formedness of the data, so it can always be re-read.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20180618/b8badfb0/attachment.html>


More information about the Development mailing list