Qt (Un)使用nlohmann/JSON序列化QObject中的JSON(to)

Qt (Un)使用nlohmann/JSON序列化QObject中的JSON(to),qt,nlohmann-json,Qt,Nlohmann Json,我想使用该库将一些json序列化为QObject,反之亦然 我遇到的问题是解析器试图使用QObject的复制构造函数,不允许使用wish 文档中有一些与此相关的内容,但我无法使其正常工作 template <> struct adl_serializer<MyQObject> { static MyQObject from_json(const json& j) { return {j.get<MyQObject>()}

我想使用该库将一些json序列化为QObject,反之亦然

我遇到的问题是解析器试图使用QObject的复制构造函数,不允许使用wish

文档中有一些与此相关的内容,但我无法使其正常工作

template <>
struct adl_serializer<MyQObject>
{
    static MyQObject from_json(const json& j)
    {
        return {j.get<MyQObject>()}; // call to implicitly-deleted copy constructor of 'MyQObject'
    }

    static void to_json(json& j, MyQObject t)
    {
        j = t; // no viable overload '='
    }
};

inline void from_json(const json& j, MyQObject& x)
{
    x.setXxx(j.at("xxx").get<typeOfXxx>()):
    // ...
}

inline void to_json(json& j, const MyQObject& x)
{
    j = json::object();
    j["xxx"] = x.xxx();
    // ...
}
模板
结构adl_序列化程序
{
来自_json的静态MyQObject(const json&j)
{
返回{j.get()};//调用“MyQObject”的隐式删除副本构造函数
}
静态void to_json(json&j,MyQObject t)
{
j=t;//没有可行的重载“=”
}
};
来自_json的内联void(const json&j、MyQObject&x)
{
x、 setXxx(j.at(“xxx”).get()):
// ...
}
内联void到_json(json&j,const MyQObject&x)
{
j=json::object();
j[“xxx”]=x.xxx();
// ...
}

我应该在adl_序列化程序中编写什么才能使其工作?

什么样的数据以及如何在
QObject
中存储?@vahancho主要是基本类型和其他QObject派生类。函数“from_json(const json&j,MyQObject&x)”用于填充QObject(如文档中所示)。您能举一个在
QObject
中存储类似json的数据的例子吗?我不想将其存储为json数据,但在对象中取消序列化。类似于
MyQObject-myObject=nlohmann::json::parse(jsonStr)
什么样的数据以及如何存储在
QObject
中?@vahancho主要是基本类型和其他QObject派生类。函数“from_json(const json&j,MyQObject&x)”用于填充QObject(如文档中所示)。您能举一个在
QObject
中存储类似json的数据的例子吗?我不想将其存储为json数据,但在对象中取消序列化。类似于
MyQObject-myObject=nlohmann::json::parse(jsonStr)