JS notation to Qt
-
The best notation to convert below code to Qt C++ is ?
https://github.com/skokov3812/encrypted-smiley-secure-protocol/blob/master/src/command.js -
@Damian7546
Yes, that principle looks good.I said the JS looked sufficiently close to JSON that you could have made a few edits in an editor (e.g. change single quotes to double quotes for strings, remove trailing commas from last elements in lists, etc.) so that you could have used Qt's JSON calls to directly read that into an auto-created JSON structure. And that is the "simplest".
But if you want an actual C++
struct
/class
, with specific typed members, for each compound entry in the source then you do indeed need to do what you show: declare a corresponding C++ structure and alter the original a little more so that you can assign to it directly in source code. But would not allow assignment from data in external file, without writing separate code for that, which the JSON would.A couple of elements in the JS you have require an additional
example
member variable, which can presumably be empty in items which do not specify it. -
@Damian7546
What sort of answer are you expecting?Looking at that JavaScript source code it is so close to JSON you could just edit it by hand to make a couple of minor changes. Then you could read it as a JSON structure from Qt's JSON support. Of course what you then do with that from C++ is a different matter.
-
Usually JSON I used to exchange data with my service.
The shown JavaScript source code I would like to "convert" to my app in qt C++ code.
@JonB What do you thing about below convert ?struct Command { int code; bool encrypted; bool args; QStringList device; QString description; }; Command RESET = { 1, false, false, {"NV9USB", "NV10USB", "BV20", "BV50", "BV100", "NV200", "SMART Hopper", "SMART Payout", "NV11"}, "Command to instruct the slave to perform a hard reset at any point within its operational status." }; etc ...
-
@Damian7546
Yes, that principle looks good.I said the JS looked sufficiently close to JSON that you could have made a few edits in an editor (e.g. change single quotes to double quotes for strings, remove trailing commas from last elements in lists, etc.) so that you could have used Qt's JSON calls to directly read that into an auto-created JSON structure. And that is the "simplest".
But if you want an actual C++
struct
/class
, with specific typed members, for each compound entry in the source then you do indeed need to do what you show: declare a corresponding C++ structure and alter the original a little more so that you can assign to it directly in source code. But would not allow assignment from data in external file, without writing separate code for that, which the JSON would.A couple of elements in the JS you have require an additional
example
member variable, which can presumably be empty in items which do not specify it. -