3

Is there a way to convert my custom object to json?

class EntityRepetitive: public EntityTreatment
{
 public:
 EntityRepetitive(int channelNum,float power,float freq,int  numOfPulses,float waitTime, int numOfTrains);
 ~EntityRepetitive();

 int channelNum;
 float power;
 float freq;
 int numOfPulses;
 float waitTime;
 int numOfTrains;
};

my cpp file:

er = new EntityRepetitive(channelNum,power,freq,numOfPulses,waitTime,numOfTrains);

I want to convert er to JsonString and vice versa.

Natile
  • 193
  • 1
  • 6
  • 20
  • possible duplicate of [Converting C++ class to JSON](http://stackoverflow.com/questions/8220130/converting-c-class-to-json) – Captain Giraffe Jun 15 '15 at 11:08
  • 1
    I ask about something built-in in qt framework – Natile Jun 15 '15 at 11:46
  • 1
    Use the Qt Json classes such as [QJsonDocument](http://doc.qt.io/qt-5/qjsondocument.html) and [QJsonObject](http://doc.qt.io/qt-5/qjsonobject.html) etc. – TheDarkKnight Jun 15 '15 at 12:14
  • There is no native way in Qt. But you can declare Q_PROPERTY for each private member and pushed them to QVariantMap. QVariantMap can be converted to json via standard Qt classes, such as QJsonObject and QJsonDocument. – synacker Jun 15 '15 at 12:43

0 Answers0