0

I'm working with Qt and JSON. Now, I have two options: QVariant and QJsonValue. I don't get the point in which they are different?

I know QVariant has some more methods and QJsonValue has the is*** methods(where QVariant has type). But is there any other main difference (maybe speed)? If no: Why are there two classes which can do nearly the same?

Dimitry Ernot
  • 6,256
  • 2
  • 25
  • 37
ratloser
  • 116
  • 1
  • 7
  • of course, Qvariant can contain more types, but why should I use QJsonvalue if there is the alternative QVariant? – ratloser May 15 '19 at 17:52
  • 2
    JsonValue is a specialized type that only allows certain types of data indicated in the standard json as strings, numbers, booleans, etc. – eyllanesc May 15 '19 at 18:21
  • Ok, I think I got it now. QJsonvalue is not that different from QVariant, but it has some small advantages. Like you said... just JSON Values inside. And what I found out right before, QJsonvalue are strictly typed -> you can't do any implicit conversions. Thanks for helping @eyllanesc – ratloser May 15 '19 at 18:25
  • 1
    Everything mentioned above is true and aside from that you can store some Qt-specific types in QVariant or register your own and store it. They may not be easily serializable to Json but could be stored in QVariant. – MasterAler May 15 '19 at 18:40

1 Answers1

-1

QVariant give you more flexibility in manipulating data.

norrr
  • 24
  • 1
  • 3