Hi all, Qt handles a broad spectrum of data both in and out of RAM and Qt users routinely need to read/write such data from/to their domain-specific C++ types. But doing so can feel much more complicated than it should be: e.g. unexpected QVariant conversions, unknown QDataStream versions, complex QAbstractItemModel requirements, specific QCborStreamReader protocol, ... Moreover, writing such boilerplate code is time-consuming, error-prone, and boring.
JSON demonstrates that having a simple data model can simplify exchanging data between software components. But it cannot meet all the technical requirements that data must meet here and there. I am proposing to add to Qt a simple-to-use (de)serialization mechanism that can achieve better write performance and read robustness than current alternatives. It does not define a new generic data type: QVariant/List/Map, Q*ItemModel, QJsonValue, ... are here to meet various sets of requirements. It just defines a generic, efficient and robust templated function to 'bind' such data with any C++ type: QBind<T> ::bind(Value&& v, T& t) It is not unit-tested but a sample and benchmark shows it can be made to work efficiently with: - Qt containers (read/write) - QMetaObject (read/write) - QVariant* (read/write) - QJsonValue (read/write) + ad-hoc JSON reader/writer - QCborValue (read/write), QCborStreamReader + ad-hoc CBOR writer - QSettings (read/write) - QXmlStreamWriter - QAbstractItemModel (write) - QDataStream (write) The simplest way to enable it for a C++ type is to use QMetaObject when available through a macro (QBIND_*_WITH_METAOBJECT). Best performance can only be attained by defining simple bind(Value&& v) methods that usually work for both read and write: https://gricad-gitlab.univ-grenoble-alpes.fr/modmed/modmedLog/blob/master/tests/QBind/README.md#extending-qbind-to-c-types Finally, since a single QBind<T> function cannot fulfill all the needs, its fluent interface allows writing custom binds akin to Python list comprehensions... I would be happy to hear if you feel like this would be a useful contribution to Qt, or to answer your technical questions and arguments. Arnaud
_______________________________________________ Development mailing list Development@qt-project.org https://lists.qt-project.org/listinfo/development