Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LeonMatthesKDAB opened this issue Apr 24, 2024 · 3 comments
Open
Labels
⬆️ feature New feature or request 🙋 good first issue Good for newcomers

Comments

@LeonMatthesKDAB
Copy link
Collaborator

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?

@LeonMatthesKDAB LeonMatthesKDAB added ⬆️ feature New feature or request 🙋 good first issue Good for newcomers labels Apr 24, 2024
LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Apr 24, 2024
@ahayzen-kdab
Copy link
Collaborator

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.

@LeonMatthesKDAB
Copy link
Collaborator Author

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.

LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Apr 24, 2024
@ahayzen-kdab
Copy link
Collaborator

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.

LeonMatthesKDAB added a commit to LeonMatthesKDAB/cxx-qt that referenced this issue Apr 24, 2024
LeonMatthesKDAB added a commit that referenced this issue May 10, 2024
See also: #943

Co-authored-by: Montel Laurent <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⬆️ feature New feature or request 🙋 good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants