"""\n#include "QJsonObject"\n#include "QJsonArray"\n\n// Helper function to convert a value to QJsonValue\ntemplate\nQJsonValue toQJsonValue(const T& value)\n{\n return QJsonValue::fromVariant(QVariant::fromValue(value));\n}\n\n// Helper function to convert a struct to QJsonObject\ntemplate\nQJsonObject toQJsonObject(const T& data)\n{\n QJsonObject jsonObject;\n\n // Iterate over each member variable in the struct\n // and add it to the QJsonObject\n QMetaObject metaObject = T::staticMetaObject;\n for (int i = 0; i < metaObject.propertyCount(); ++i) {\n QMetaProperty metaProperty = metaObject.property(i);\n const char* propertyName = metaProperty.name();\n QVariant propertyValue = metaProperty.readOnGadget(&data);\n\n // Handle different data types\n if (propertyValue.type() == QVariant::List) {\n QJsonArray jsonArray;\n QList list = propertyValue.toList();\n for (const QVariant& element : list) {\n jsonArray.append(toQJsonValue(element));\n }\n jsonObject[propertyName] = jsonArray;\n } else if (propertyValue.type() == QVariant::Map) {\n QJsonObject nestedJsonObject;\n QMap<QString, QVariant> map = propertyValue.toMap();\n for (const QString& key : map.keys()) {\n nestedJsonObject[key] = toQJsonValue(map.value(key));\n }\n jsonObject[propertyName] = nestedJsonObject;\n } else {\n jsonObject[propertyName] = toQJsonValue(propertyValue);\n }\n }\n\n return jsonObject;\n}\n"""\n\nTo use this template, you need to define your struct with Q_GADGET macro and add Q_PROPERTY declarations for each member variable. Here's an example:\n\n"""\n#include "QDebug"\n\nstruct MyStruct {\n Q_GADGET\n Q_PROPERTY(QString name MEMBER name)\n Q_PROPERTY(int age MEMBER age)\n Q_PROPERTY(QList hobbies MEMBER hobbies)\n Q_PROPERTY(QMap<QString, QVariant> data MEMBER data)\n\npublic:\n QString name;\n int age;\n QList hobbies;\n QMap<QString, QVariant> data;\n};\n\nint main()\n{\n MyStruct myStruct;\n myStruct.name = "John";\n myStruct.age = 25;\n myStruct.hobbies = {"Reading", "Gaming"};\n myStruct.data = {{"key1", 10}, {"key2", "value"}};\n\n QJsonObject jsonObject = toQJsonObject(myStruct);\n qDebug() << jsonObject;\n\n return 0;\n}\n"""\n\nThis template will automatically convert the struct to a QJsonObject, handling different data types such as QString, int, QList, QMap, etc.