Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Using QPair in struct



  • 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{});
    


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



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


Log in to reply