Git Product home page Git Product logo

Comments (5)

arietto avatar arietto commented on July 20, 2024

Oh, it was introduced in Qt 5.10. Then you should add info about it to your manual.
http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/kernel/qmetatype.h?h=5.10

from qtjsonserializer.

Skycoder42 avatar Skycoder42 commented on July 20, 2024

Interesting. This can definitly be added in a future version. When I created this library, gadget pointers where not supported yet.

If you have the time, you can create a pull request for that. You will most likely have to adjust https://github.com/Skycoder42/QtJsonSerializer/blob/master/src/jsonserializer/typeconverters/qjsongadgetconverter.cpp sligthly so it can handle both versions, value and pointer gadgets, as the code to serialize the gadget itself wont change, just how to get the gadget from QVariant.

from qtjsonserializer.

arietto avatar arietto commented on July 20, 2024

Ok, and what about Q_GADGET written as QSharedPointer<MyGadget> m_gadget? If I use special property for it (with custom getter/setter), then should I prefer QJsonValue over QVariant for properties to minimize intermediate conversions?

from qtjsonserializer.

Skycoder42 avatar Skycoder42 commented on July 20, 2024

Yes, you can of cause create a "dummy property" that returns a generic value and use it as a local converter.

If you do the conversion yourself, it doesn't matter that, as long as you only use "primitive variants" (i.e. QString, int, QVariantMap, QVariantList) - however I would recommend to use QJsonValue anyways, as this prevents you from accidentially returning a non trivial variant and makes it obvious what the methods do.

I typically use the following pattern:

Q_PROPERTY(QJsonValue myGadget READ getMyGadget WRITE setMyGadget)
// and optionally, if you still want to use the gadget from the property system
Q_PROPERTY(QSharedPointer<MyGadget> _myGadget MEMBER m_gadget STORED false)

from qtjsonserializer.

Skycoder42 avatar Skycoder42 commented on July 20, 2024

Support for plain gadget pointers was added. Smart gadget pointers are currently not supported by Qt, as QMetaType::PointerToGadget only works for plain pointers.

Please note that when deserializing a gadget pointer, it is internally allocated using new and thus must be deleted by the caller.

Even with this, polymorphic gadgets are not supported for the same reason as in #8. However, using gadget pointers will propably make it much easier to actually implement those in a project

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.