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. Using QPair in struct
Forum Updated to NodeBB v4.3 + New Features

Using QPair in struct

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 301 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.
  • K Offline
    K Offline
    Kris Revi
    wrote on 16 Sept 2020, 19:47 last edited by
    #1

    so in python i have this struct

            self.pattern = {
                'SOLIDCOLOR':{'hightlightButton':[1, 'BUTTON_PATTERN_SOLIDCOLOR'], 'setDefaults':[0, 2],  'EnableFeatures':[True, False, False, True, True, True, True, True],  'selectedPattern':1},
                'RAINBOW':{'hightlightButton':[2, 'BUTTON_PATTERN_RAINBOW'], 'setDefaults':[25, 2],  'EnableFeatures':[True, True, False, False, False, False, True, False],  'selectedPattern':2},
                'THEATERCHASE':{'hightlightButton':[3, 'BUTTON_PATTERN_THEATERCHASE'], 'setDefaults':[127, 3],  'EnableFeatures':[True, True, True, True, True, True, True, True],  'selectedPattern':3},
                'JUGGLE':{'hightlightButton':[4, 'BUTTON_PATTERN_JUGGLE'], 'setDefaults':[0, 2],  'EnableFeatures':[True, False, False, False, False, False, True, False],  'selectedPattern':4},
                'RUNNINGLIGHT':{'hightlightButton':[5, 'BUTTON_PATTERN_RUNNINGLIGHTS'], 'setDefaults':[25, 10],  'EnableFeatures':[True, True, True, True, True, True, True, True],  'selectedPattern':5},
                'CYLON':{'hightlightButton':[6, 'BUTTON_PATTERN_CYLON'], 'setDefaults':[50, 2],  'EnableFeatures':[True, True, True, True, True, True, True, True],  'selectedPattern':6},
                'MITOSIS':{'hightlightButton':[7, 'BUTTON_PATTERN_MITOSIS'], 'setDefaults':[50, 199],  'EnableFeatures':[True, True, True, True, True, True, True, True],  'selectedPattern':7},
            }
    

    and in Qt i've come up with this with a bit of help

    struct Pattern
    {
        QPair<int, QString> hightlightButton;
        QPair<int, int> setDefaults;
        QVector<bool> enableFeatures;
        int selectedPattern;
    };
    

    but im unsure how to insert this line

    [1, 'BUTTON_PATTERN_SOLIDCOLOR']
    

    into

        QMap<QString, Pattern> pattern;
        pattern.insert("SOLIDCOLOR", Pattern{});
    
    P 1 Reply Last reply 17 Sept 2020, 02:20
    0
    • K Kris Revi
      16 Sept 2020, 19:47

      so in python i have this struct

              self.pattern = {
                  'SOLIDCOLOR':{'hightlightButton':[1, 'BUTTON_PATTERN_SOLIDCOLOR'], 'setDefaults':[0, 2],  'EnableFeatures':[True, False, False, True, True, True, True, True],  'selectedPattern':1},
                  'RAINBOW':{'hightlightButton':[2, 'BUTTON_PATTERN_RAINBOW'], 'setDefaults':[25, 2],  'EnableFeatures':[True, True, False, False, False, False, True, False],  'selectedPattern':2},
                  'THEATERCHASE':{'hightlightButton':[3, 'BUTTON_PATTERN_THEATERCHASE'], 'setDefaults':[127, 3],  'EnableFeatures':[True, True, True, True, True, True, True, True],  'selectedPattern':3},
                  'JUGGLE':{'hightlightButton':[4, 'BUTTON_PATTERN_JUGGLE'], 'setDefaults':[0, 2],  'EnableFeatures':[True, False, False, False, False, False, True, False],  'selectedPattern':4},
                  'RUNNINGLIGHT':{'hightlightButton':[5, 'BUTTON_PATTERN_RUNNINGLIGHTS'], 'setDefaults':[25, 10],  'EnableFeatures':[True, True, True, True, True, True, True, True],  'selectedPattern':5},
                  'CYLON':{'hightlightButton':[6, 'BUTTON_PATTERN_CYLON'], 'setDefaults':[50, 2],  'EnableFeatures':[True, True, True, True, True, True, True, True],  'selectedPattern':6},
                  'MITOSIS':{'hightlightButton':[7, 'BUTTON_PATTERN_MITOSIS'], 'setDefaults':[50, 199],  'EnableFeatures':[True, True, True, True, True, True, True, True],  'selectedPattern':7},
              }
      

      and in Qt i've come up with this with a bit of help

      struct Pattern
      {
          QPair<int, QString> hightlightButton;
          QPair<int, int> setDefaults;
          QVector<bool> enableFeatures;
          int selectedPattern;
      };
      

      but im unsure how to insert this line

      [1, 'BUTTON_PATTERN_SOLIDCOLOR']
      

      into

          QMap<QString, Pattern> pattern;
          pattern.insert("SOLIDCOLOR", Pattern{});
      
      P Offline
      P Offline
      Pl45m4
      wrote on 17 Sept 2020, 02:20 last edited by Pl45m4
      #2

      @Kris-Revi

      Since it seems a bit complicated to keep an overview over all these mapped values, arrays and strings, I would change your struct to a class (unless there is some reason, why you can't do that). But depends on you, how you want to handle your data.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • B Offline
        B Offline
        Bonnie
        wrote on 17 Sept 2020, 02:22 last edited by
        #3

        Your pattern seems to be json, so why don't you simply use QJsonObject / QJsonArray?

        1 Reply Last reply
        4

        1/3

        16 Sept 2020, 19:47

        • Login

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