Git Product home page Git Product logo

Comments (3)

Skycoder42 avatar Skycoder42 commented on July 20, 2024

I'm not exactly shure what you are asking, but I'll try to answer anyways.

Where the Enum is defined does not really matter for serializing, as long as the Q_ENUM macro is used (which it is for your example). Now all that needs to be done is declare the Q_PROPERTY with the enums full qualified name as type:

struct MySecondGadget
{
    Q_GADGET

    Q_PROPERTY(MyEnumWrapper::Enum myEnumField MEMBER myEnumField)

public:
    MyEnumWrapper::Enum myEnumField;
};

Q_DECLARE_METATYPE(MySecondGadget)

To ensure it works as intended, you should also register the gadget wrapper as metatype (As you should do with all your gadgets). Use Q_DECLARE_METATYPE(MyEnumWrapper) in the header and qRegisterMetaType<MyEnumWrapper>(); in your main.cpp. Finally, use the setEnumAsString(true); as you already mentioned, and your good to go.

Note: In case you have to use flags, use Q_PROPERTY(MyEnumWrapper::Flags myflagsField READ getField WRITE setFiled) instead, as member access for flags is broken. But for classic enums, using the member should suffice.

from qtjsonserializer.

arietto avatar arietto commented on July 20, 2024

Thank you for your full answer. BTW, I've tried to disable Q_DECLARE_METATYPE(MyEnumWrapper) and qRegisterMetaType<MyEnumWrapper>();. It worked even without them.

from qtjsonserializer.

Skycoder42 avatar Skycoder42 commented on July 20, 2024

Good to know. It's sometimes hard to know what works with the registrations and what not. Thats why I just always add them, to be on the safe side.

from qtjsonserializer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.