KDAB/cxx-qt

Add `serde` support for cxx-qt-lib using `#[serde(into=...,from=...)]`

Opened this issue · 3 comments

Serde supports automatically converting types after/before (de-)serialization to a proxy type.

This way, we could more easily support Serde in cxx-qt-lib, after our previous failed attempts in #425 .
It would be somewhat less optimal, as e.g. serializing a QString would mean a conversion to/from String, but still better than not supporting it.

@Montel does this sound like a feature you'd be interested in adding?

I think the question for some of them is what JSON format should we use, as eg QJsonValue doesn't have an implementation for QPoint, so should we just {"x": 1, "y": 2} or [1, 2] etc etc.

The exact output format is decided by the serializer, which is unrelated to JSON, but the question remains what types to convert to which native Rust types.

In the case of QPoint, we can actually just use #[derive(Serialize,Deserialize)] directly, as we've implemented it as a trivial type.

In the case of JSON, this would result in {"x": 1, "y": 2}, which is the right way to implement this using serde.
If you want to parse your own custom format, you'll have to roll your own Deserialize implementation anyway.

Right, I guess it's things like color which can be tricky and things where even the Qt internals aren't consistent like QRect vs QRectF.