Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. JS notation to Qt
Forum Updated to NodeBB v4.3 + New Features

JS notation to Qt

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 232 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Damian7546
    wrote on last edited by
    #1

    The best notation to convert below code to Qt C++ is ?
    https://github.com/skokov3812/encrypted-smiley-secure-protocol/blob/master/src/command.js

    JonBJ 1 Reply Last reply
    0
    • D Damian7546

      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 ... 
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #4

      @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.

      1 Reply Last reply
      0
      • D Damian7546

        The best notation to convert below code to Qt C++ is ?
        https://github.com/skokov3812/encrypted-smiley-secure-protocol/blob/master/src/command.js

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @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.

        D 1 Reply Last reply
        3
        • JonBJ JonB

          @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.

          D Offline
          D Offline
          Damian7546
          wrote on last edited by Damian7546
          #3

          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 ... 
          
          JonBJ 1 Reply Last reply
          1
          • D Damian7546

            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 ... 
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @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.

            1 Reply Last reply
            0
            • D Damian7546 has marked this topic as solved on

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved