Writing to json file, output wrong!
-
wrote on 9 Apr 2023, 13:38 last edited by
my problem is that the json that gets written to the json file is wrong
As you can see first off
"Pattern": []
is at the bottom for some reason and second if you start at the the top it starts at ID 0,1 then suddenly 10 and then suddenly 100now i know im doing something wrong but atm i cannot see what, why and where! please help me!
{ "0": { "id": 0, "image": ":/image/patterns/FX_000.gif", "name": "SOLID", "tooltip": "", "type": "1D" }, "1": { "id": 1, "image": ":/image/patterns/FX_001.gif", "name": "BLINK", "tooltip": "", "type": "1D" }, "10": { "id": 10, "image": ":/image/patterns/FX_010.gif", "name": "SCAN", "tooltip": "", "type": "1D" }, "100": { "id": 100, "image": ":/image/patterns/FX_100.gif", "name": "HEARTBEAT", "tooltip": "", "type": "1D" }, "101": { "id": 101, "image": ":/image/patterns/FX_101.gif", "name": "PACIFICA", "tooltip": "", "type": "1D" }, "102": { "id": 102, "image": ":/image/patterns/FX_102.gif", "name": "CANDLEMULTI", "tooltip": "", "type": "1D" }, "103": { "id": 103, "image": ":/image/patterns/FX_103.gif", "name": "SOLIDGLITTER", "tooltip": "", "type": "1D" }, "104": { "id": 104, "image": ":/image/patterns/FX_104.gif", "name": "SUNRISE", "tooltip": "", "type": "1D" }, "105": { "id": 105, "image": ":/image/patterns/FX_105.gif", "name": "PHASED", "tooltip": "", "type": "1D" }, "106": { "id": 106, "image": ":/image/patterns/FX_106.gif", "name": "TWINKLEUP", "tooltip": "", "type": "1D" }, "107": { "id": 107, "image": ":/image/patterns/FX_107.gif", "name": "NOISEPAL", "tooltip": "", "type": "1D" }, "108": { "id": 108, "image": ":/image/patterns/FX_108.gif", "name": "SINEWAVE", "tooltip": "", "type": "1D" }, "109": { "id": 109, "image": ":/image/patterns/FX_109.gif", "name": "PHASEDNOISE", "tooltip": "", "type": "1D" }, "11": { "id": 11, "image": ":/image/patterns/FX_011.gif", "name": "DUALSCAN", "tooltip": "", "type": "1D" }, "110": { "id": 110, "image": ":/image/patterns/FX_110.gif", "name": "FLOW", "tooltip": "", "type": "1D" }, "111": { "id": 111, "image": ":/image/patterns/FX_111.gif", "name": "CHUNCHUN", "tooltip": "", "type": "1D" }, "112": { "id": 112, "image": ":/image/patterns/FX_112.gif", "name": "DANCINGSHADOWS", "tooltip": "", "type": "1D" }, "113": { "id": 113, "image": ":/image/patterns/FX_113.gif", "name": "WASHINGMACHINE", "tooltip": "", "type": "1D" }, "114": { "id": 114, "image": ":/image/patterns/FX_114.gif", "name": "", "tooltip": "", "type": "1D" }, "115": { "id": 115, "image": ":/image/patterns/FX_115.gif", "name": "BLENDS", "tooltip": "", "type": "1D" }, "116": { "id": 116, "image": ":/image/patterns/FX_116.gif", "name": "TVSIMULATOR", "tooltip": "", "type": "1D" }, "117": { "id": 117, "image": ":/image/patterns/FX_117.gif", "name": "DYNAMICSMOOTH", "tooltip": "", "type": "1D" }, "118": { "id": 118, "image": ":/image/patterns/FX_118.gif", "name": "SPACESHIPS", "tooltip": "", "type": "2D" }, "119": { "id": 119, "image": ":/image/patterns/FX_119.gif", "name": "CRAZYBEES", "tooltip": "", "type": "2D" }, "12": { "id": 12, "image": ":/image/patterns/FX_012.gif", "name": "FADE", "tooltip": "", "type": "1D" }, "120": { "id": 120, "image": ":/image/patterns/FX_120.gif", "name": "GHOSTRIDER", "tooltip": "", "type": "2D" }, "121": { "id": 121, "image": ":/image/patterns/FX_121.gif", "name": "LOBS", "tooltip": "", "type": "2D" }, "122": { "id": 122, "image": ":/image/patterns/FX_122.gif", "name": "SCROLLname", "tooltip": "", "type": "2D" }, "123": { "id": 123, "image": ":/image/patterns/FX_123.gif", "name": "DRIFTROSE", "tooltip": "", "type": "2D" }, "124": { "id": 124, "image": ":/image/patterns/FX_124.gif", "name": "DISTORTIONWAVES", "tooltip": "", "type": "2D" }, "125": { "id": 125, "image": ":/image/patterns/FX_125.gif", "name": "", "tooltip": "", "type": "SR" }, "126": { "id": 126, "image": ":/image/patterns/FX_126.gif", "name": "", "tooltip": "", "type": "SR" }, "127": { "id": 127, "image": ":/image/patterns/FX_127.gif", "name": "", "tooltip": "", "type": "SR" }, "128": { "id": 128, "image": ":/image/patterns/FX_128.gif", "name": "PIXELS", "tooltip": "", "type": "SR" }, "129": { "id": 129, "image": ":/image/patterns/FX_129.gif", "name": "PIXELWAVE", "tooltip": "", "type": "SR" }, "13": { "id": 13, "image": ":/image/patterns/FX_013.gif", "name": "THEATERCHASE", "tooltip": "", "type": "1D" }, "130": { "id": 130, "image": ":/image/patterns/FX_130.gif", "name": "JUGGLES", "tooltip": "", "type": "SR" } "Pattern": [ ] }
Function :
void Filemanager::initPatternMenu() { QFile file(savePath + folderData + fileJsonPattern); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { FileManagerDebugger.LevelInfo("PATTERNDATA", "Making File", "!"); struct Pattern { int id; QString type, name, image, tooltip; }; QVector<Pattern> patterns = { {0,"1D","SOLID",":/image/patterns/FX_000.gif",""}, {1,"1D","BLINK",":/image/patterns/FX_001.gif",""}, {2,"1D","BREATHE",":/image/patterns/FX_002.gif",""}, {3,"1D","WIPE",":/image/patterns/FX_003.gif",""}, {4,"1D","WIPERANDOM",":/image/patterns/FX_004.gif",""}, {5,"1D","RANDOMCOLORS",":/image/patterns/FX_005.gif",""}, {6,"1D","COLORSWEEP",":/image/patterns/FX_006.gif",""}, {7,"1D","DYNAMIC",":/image/patterns/FX_007.gif",""}, {8,"1D","RAINBOW",":/image/patterns/FX_008.gif",""}, {9,"1D","RAINBOWCYCLE",":/image/patterns/FX_009.gif",""}, {10,"1D","SCAN",":/image/patterns/FX_010.gif",""}, {11,"1D","DUALSCAN",":/image/patterns/FX_011.gif",""}, {12,"1D","FADE",":/image/patterns/FX_012.gif",""}, {13,"1D","THEATERCHASE",":/image/patterns/FX_013.gif",""}, {14,"1D","THEATERCHASERAINBOW",":/image/patterns/FX_014.gif",""}, {15,"1D","RUNNINGLIGHTS",":/image/patterns/FX_015.gif",""}, {16,"1D","SAW",":/image/patterns/FX_016.gif",""}, {17,"1D","TWINKLE",":/image/patterns/FX_017.gif",""}, {18,"1D","DISSOLVE",":/image/patterns/FX_018.gif",""}, {19,"1D","DISSOLVERANDOM",":/image/patterns/FX_019.gif",""}, {20,"1D","SPARKLE",":/image/patterns/FX_020.gif",""}, {21,"1D","SPARKLEFLASH",":/image/patterns/FX_021.gif",""}, {22,"1D","SPARKLEHYPER",":/image/patterns/FX_022.gif",""}, {23,"1D","STROBE",":/image/patterns/FX_023.gif",""}, {24,"1D","STROBERAINBOW",":/image/patterns/FX_024.gif",""}, {25,"1D","STROBEMULTI",":/image/patterns/FX_025.gif",""}, {26,"1D","BLINKRAINBOW",":/image/patterns/FX_026.gif",""}, {27,"1D","ANDROID",":/image/patterns/FX_027.gif",""}, {28,"1D","CHASECOLOR",":/image/patterns/FX_028.gif",""}, {29,"1D","CHASERANDOM",":/image/patterns/FX_029.gif",""}, {30,"1D","CHASERAINBOW",":/image/patterns/FX_030.gif",""}, {31,"1D","CHASEFLASH",":/image/patterns/FX_031.gif",""}, {32,"1D","CHASEFLASHRANDOM",":/image/patterns/FX_032.gif",""}, {33,"1D","CHASERAINBOWWHITE",":/image/patterns/FX_033.gif",""}, {34,"1D","COLORFUL",":/image/patterns/FX_034.gif",""}, {35,"1D","TRAFFICLIGHT",":/image/patterns/FX_035.gif",""}, {36,"1D","COLORSWEEPRANDOM",":/image/patterns/FX_036.gif",""}, {37,"1D","RUNNINGCOLOR",":/image/patterns/FX_037.gif",""}, {38,"1D","AURORA",":/image/patterns/FX_038.gif",""}, {39,"1D","RUNNINGRANDOM",":/image/patterns/FX_039.gif",""}, {40,"1D","LARSONSCANNER",":/image/patterns/FX_040.gif",""}, {41,"1D","COMET",":/image/patterns/FX_041.gif",""}, {42,"1D","FIREWORKS",":/image/patterns/FX_042.gif",""}, {43,"1D","RAIN",":/image/patterns/FX_043.gif",""}, {44,"1D","TETRIX",":/image/patterns/FX_044.gif",""}, {45,"1D","FIREFLICKER",":/image/patterns/FX_045.gif",""}, {46,"1D","GRADIENT",":/image/patterns/FX_046.gif",""}, {47,"1D","LOADING",":/image/patterns/FX_047.gif",""}, {48,"1D","",":/image/patterns/FX_048.gif",""}, {49,"1D","FAIRY",":/image/patterns/FX_049.gif",""}, {50,"1D","TWODOTS",":/image/patterns/FX_050.gif",""}, {51,"1D","FAIRYTWINKLE",":/image/patterns/FX_051.gif",""}, {52,"1D","RUNNINGDUAL",":/image/patterns/FX_052.gif",""}, {53,"1D","",":/image/patterns/FX_053.gif",""}, {54,"1D","TRICOLORCHASE",":/image/patterns/FX_054.gif",""}, {55,"1D","TRICOLORWIPE",":/image/patterns/FX_055.gif",""}, {56,"1D","TRICOLORFADE",":/image/patterns/FX_056.gif",""}, {57,"1D","LIGHTNING",":/image/patterns/FX_057.gif",""}, {58,"1D","ICU",":/image/patterns/FX_058.gif",""}, {59,"1D","MULTICOMET",":/image/patterns/FX_059.gif",""}, {60,"1D","DUALLARSONSCANNER",":/image/patterns/FX_060.gif",""}, {61,"1D","RANDOMCHASE",":/image/patterns/FX_061.gif",""}, {62,"1D","OSCILLATE",":/image/patterns/FX_062.gif",""}, {63,"1D","PRIDE2015",":/image/patterns/FX_063.gif",""}, {64,"1D","JUGGLE",":/image/patterns/FX_064.gif",""}, {65,"1D","PALETTE",":/image/patterns/FX_065.gif",""}, {66,"1D","FIRE2012",":/image/patterns/FX_066.gif",""}, {67,"1D","COLORWAVES",":/image/patterns/FX_067.gif",""}, {68,"1D","BPM",":/image/patterns/FX_068.gif",""}, {69,"1D","FILLNOISE8",":/image/patterns/FX_069.gif",""}, {70,"1D","NOISE161",":/image/patterns/FX_070.gif",""}, {71,"1D","NOISE162",":/image/patterns/FX_071.gif",""}, {72,"1D","NOISE163",":/image/patterns/FX_072.gif",""}, {73,"1D","NOISE164",":/image/patterns/FX_073.gif",""}, {74,"1D","COLORTWINKLE",":/image/patterns/FX_074.gif",""}, {75,"1D","LAKE",":/image/patterns/FX_075.gif",""}, {76,"1D","METEOR",":/image/patterns/FX_076.gif",""}, {77,"1D","METEORSMOOTH",":/image/patterns/FX_077.gif",""}, {78,"1D","RAILWAY",":/image/patterns/FX_078.gif",""}, {79,"1D","RIPPLE",":/image/patterns/FX_079.gif",""}, {80,"1D","TWINKLEFOX",":/image/patterns/FX_080.gif",""}, {81,"1D","TWINKLECAT",":/image/patterns/FX_081.gif",""}, {82,"1D","HALLOWEENEYES",":/image/patterns/FX_082.gif",""}, {83,"1D","STATICPATTERN",":/image/patterns/FX_083.gif",""}, {84,"1D","TRISTATICPATTERN",":/image/patterns/FX_084.gif",""}, {85,"1D","SPOTS",":/image/patterns/FX_085.gif",""}, {86,"1D","SPOTSFADE",":/image/patterns/FX_086.gif",""}, {87,"1D","GLITTER",":/image/patterns/FX_087.gif",""}, {88,"1D","CANDLE",":/image/patterns/FX_088.gif",""}, {89,"1D","STARBURST",":/image/patterns/FX_089.gif",""}, {90,"1D","EXPLODINGFIREWORKS",":/image/patterns/FX_090.gif",""}, {91,"1D","BOUNCINGBALLS",":/image/patterns/FX_091.gif",""}, {92,"1D","SINELON",":/image/patterns/FX_092.gif",""}, {93,"1D","SINELONDUAL",":/image/patterns/FX_093.gif",""}, {94,"1D","SINELONRAINBOW",":/image/patterns/FX_094.gif",""}, {95,"1D","POPCORN",":/image/patterns/FX_095.gif",""}, {96,"1D","DRIP",":/image/patterns/FX_096.gif",""}, {97,"1D","PLASMA",":/image/patterns/FX_097.gif",""}, {98,"1D","PERCENT",":/image/patterns/FX_098.gif",""}, {99,"1D","RIPPLE_RAINBOW",":/image/patterns/FX_099.gif",""}, {100,"1D","HEARTBEAT",":/image/patterns/FX_100.gif",""}, {101,"1D","PACIFICA",":/image/patterns/FX_101.gif",""}, {102,"1D","CANDLEMULTI",":/image/patterns/FX_102.gif",""}, {103,"1D","SOLIDGLITTER",":/image/patterns/FX_103.gif",""}, {104,"1D","SUNRISE",":/image/patterns/FX_104.gif",""}, {105,"1D","PHASED",":/image/patterns/FX_105.gif",""}, {106,"1D","TWINKLEUP",":/image/patterns/FX_106.gif",""}, {107,"1D","NOISEPAL",":/image/patterns/FX_107.gif",""}, {108,"1D","SINEWAVE",":/image/patterns/FX_108.gif",""}, {109,"1D","PHASEDNOISE",":/image/patterns/FX_109.gif",""}, {110,"1D","FLOW",":/image/patterns/FX_110.gif",""}, {111,"1D","CHUNCHUN",":/image/patterns/FX_111.gif",""}, {112,"1D","DANCINGSHADOWS",":/image/patterns/FX_112.gif",""}, {113,"1D","WASHINGMACHINE",":/image/patterns/FX_113.gif",""}, {114,"1D","",":/image/patterns/FX_114.gif",""}, {115,"1D","BLENDS",":/image/patterns/FX_115.gif",""}, {116,"1D","TVSIMULATOR",":/image/patterns/FX_116.gif",""}, {117,"1D","DYNAMICSMOOTH",":/image/patterns/FX_117.gif",""}, {118,"2D","SPACESHIPS",":/image/patterns/FX_118.gif",""}, {119,"2D","CRAZYBEES",":/image/patterns/FX_119.gif",""}, {120,"2D","GHOSTRIDER",":/image/patterns/FX_120.gif",""}, {121,"2D","LOBS",":/image/patterns/FX_121.gif",""}, {122,"2D","SCROLLname",":/image/patterns/FX_122.gif",""}, {123,"2D","DRIFTROSE",":/image/patterns/FX_123.gif",""}, {124,"2D","DISTORTIONWAVES",":/image/patterns/FX_124.gif",""}, {125,"SR","",":/image/patterns/FX_125.gif",""}, {126,"SR","",":/image/patterns/FX_126.gif",""}, {127,"SR","",":/image/patterns/FX_127.gif",""}, {128,"SR","PIXELS",":/image/patterns/FX_128.gif",""}, {129,"SR","PIXELWAVE",":/image/patterns/FX_129.gif",""}, {130,"SR","JUGGLES",":/image/patterns/FX_130.gif",""}, {131,"SR","MATRIPIX",":/image/patterns/FX_131.gif",""}, {132,"SR","GRAVIMETER",":/image/patterns/FX_132.gif",""}, {133,"SR","PLASMOID",":/image/patterns/FX_133.gif",""}, {134,"SR","PUDDLES",":/image/patterns/FX_134.gif",""}, {135,"SR","MIDNOISE",":/image/patterns/FX_135.gif",""}, {136,"SR","NOISEMETER",":/image/patterns/FX_136.gif",""}, {137,"SR","FREQWAVE",":/image/patterns/FX_137.gif",""}, {138,"SR","FREQMATRIX",":/image/patterns/FX_138.gif",""}, {139,"SR 2D","GEQ",":/image/patterns/FX_139.gif",""}, {140,"SR","WATERFALL",":/image/patterns/FX_140.gif",""}, {141,"SR","FREQPIXELS",":/image/patterns/FX_141.gif",""}, {142,"SR","BINMAP",":/image/patterns/FX_142.gif",""}, {143,"SR","NOISEFIRE",":/image/patterns/FX_143.gif",""}, {144,"SR","PUDDLEPEAK",":/image/patterns/FX_144.gif",""}, {145,"SR","NOISEMOVE",":/image/patterns/FX_145.gif",""}, {146,"SR 2D","NOISE",":/image/patterns/FX_146.gif",""}, {147,"SR","PERLINMOVE",":/image/patterns/FX_147.gif",""}, {148,"SR","RIPPLEPEAK",":/image/patterns/FX_148.gif",""}, {149,"SR 2D","FIRENOISE",":/image/patterns/FX_149.gif",""}, {150,"SR 2D","SQUAREDSWIRL",":/image/patterns/FX_150.gif",""}, {151,"SR 2D","FIRE2012",":/image/patterns/FX_151.gif",""}, {152,"SR 2D","DNA",":/image/patterns/FX_152.gif",""}, {153,"SR 2D","MATRIX",":/image/patterns/FX_153.gif",""}, {154,"SR 2D","METABALLS",":/image/patterns/FX_154.gif",""}, {155,"SR","FREQMAP",":/image/patterns/FX_155.gif",""}, {156,"SR","GRAVCENTER",":/image/patterns/FX_156.gif",""}, {157,"SR","GRAVCENTRIC",":/image/patterns/FX_157.gif",""}, {158,"SR","GRAVFREQ",":/image/patterns/FX_158.gif",""}, {159,"SR","DJLIGHT",":/image/patterns/FX_159.gif",""}, {160,"SR 2D","FUNKYPLANK",":/image/patterns/FX_160.gif",""}, {161,"SR 2D","CENTERBARS",":/image/patterns/FX_161.gif",""}, {162,"SR 2D","PULSER",":/image/patterns/FX_162.gif",""}, {163,"SR","BLURZ",":/image/patterns/FX_163.gif",""}, {164,"SR 2D","DRIFT",":/image/patterns/FX_164.gif",""}, {164,"SR 2D","WAVERLY",":/image/patterns/FX_164.gif",""}, {166,"SR 2D","SUNRADIATION",":/image/patterns/FX_166.gif",""}, {167,"SR 2D","COLOREDBURSTS",":/image/patterns/FX_167.gif",""}, {168,"SR 2D","JULIA",":/image/patterns/FX_168.gif",""}, {169,"SR","",":/image/patterns/FX_169.gif",""}, {170,"SR","",":/image/patterns/FX_170.gif",""}, {171,"SR","",":/image/patterns/FX_171.gif",""}, {172,"SR 2D","GAMEOFLIFE",":/image/patterns/FX_172.gif",""}, {173,"SR 2D","TARTAN",":/image/patterns/FX_173.gif",""}, {174,"SR 2D","POLARLIGHTS",":/image/patterns/FX_174.gif",""}, {175,"SR 2D","SWIRL",":/image/patterns/FX_175.gif",""}, {176,"SR 2D","LISSAJOUS",":/image/patterns/FX_176.gif",""}, {177,"SR 2D","FRIZZLES",":/image/patterns/FX_177.gif",""}, {178,"SR 2D","PLASMABALL",":/image/patterns/FX_178.gif",""}, {179,"SR","FLOWSTRIPE",":/image/patterns/FX_179.gif",""}, {180,"SR 2D","HIPHOTIC",":/image/patterns/FX_180.gif",""}, {181,"SR 2D","SINDOTS",":/image/patterns/FX_181.gif",""}, {182,"SR 2D","DNASPIRAL",":/image/patterns/FX_182.gif",""}, {183,"SR 2D","BLACKHOLE",":/image/patterns/FX_183.gif",""}, {184,"SR","WAVESINS",":/image/patterns/FX_184.gif",""}, {185,"SR","ROCKTAVES",":/image/patterns/FX_185.gif",""}, {186,"SR 2D","AKEMI",":/image/patterns/FX_186.gif",""} }; QJsonParseError error; QJsonDocument inputJsonDoc = QJsonDocument::fromJson(file.readAll(), &error); QJsonObject top = inputJsonDoc.object(); QJsonArray patt = top.value( "Pattern" ).toArray(); top.insert("Pattern", patt); for (const auto& pattern : patterns) { QJsonObject patternObject; patternObject.insert("id", pattern.id); patternObject.insert("type", pattern.type); patternObject.insert("name", pattern.name); patternObject.insert("image", pattern.image); patternObject.insert("tooltip", pattern.tooltip); top.insert(QString::number(pattern.id), patternObject); } QJsonDocument outputJsonDoc( top ); file.write(outputJsonDoc.toJson()); file.close(); } }
-
wrote on 9 Apr 2023, 16:38 last edited by
i fixed it by myself
QJsonParseError error; QJsonDocument inputJsonDoc = QJsonDocument::fromJson(file.readAll(), &error); QJsonObject top = inputJsonDoc.object(); QJsonArray patt = top.value( "Pattern" ).toArray(); for (const auto& pattern : patterns) { QJsonObject patternObject; patternObject.insert("id", pattern.id); patternObject.insert("type", pattern.type); patternObject.insert("name", pattern.name); patternObject.insert("image", pattern.image); patternObject.insert("tooltip", pattern.tooltip); patt.append(patternObject); } top.insert("Pattern", patt); QJsonDocument outputJsonDoc( top ); file.write(outputJsonDoc.toJson()); file.close(); }
-
my problem is that the json that gets written to the json file is wrong
As you can see first off
"Pattern": []
is at the bottom for some reason and second if you start at the the top it starts at ID 0,1 then suddenly 10 and then suddenly 100now i know im doing something wrong but atm i cannot see what, why and where! please help me!
{ "0": { "id": 0, "image": ":/image/patterns/FX_000.gif", "name": "SOLID", "tooltip": "", "type": "1D" }, "1": { "id": 1, "image": ":/image/patterns/FX_001.gif", "name": "BLINK", "tooltip": "", "type": "1D" }, "10": { "id": 10, "image": ":/image/patterns/FX_010.gif", "name": "SCAN", "tooltip": "", "type": "1D" }, "100": { "id": 100, "image": ":/image/patterns/FX_100.gif", "name": "HEARTBEAT", "tooltip": "", "type": "1D" }, "101": { "id": 101, "image": ":/image/patterns/FX_101.gif", "name": "PACIFICA", "tooltip": "", "type": "1D" }, "102": { "id": 102, "image": ":/image/patterns/FX_102.gif", "name": "CANDLEMULTI", "tooltip": "", "type": "1D" }, "103": { "id": 103, "image": ":/image/patterns/FX_103.gif", "name": "SOLIDGLITTER", "tooltip": "", "type": "1D" }, "104": { "id": 104, "image": ":/image/patterns/FX_104.gif", "name": "SUNRISE", "tooltip": "", "type": "1D" }, "105": { "id": 105, "image": ":/image/patterns/FX_105.gif", "name": "PHASED", "tooltip": "", "type": "1D" }, "106": { "id": 106, "image": ":/image/patterns/FX_106.gif", "name": "TWINKLEUP", "tooltip": "", "type": "1D" }, "107": { "id": 107, "image": ":/image/patterns/FX_107.gif", "name": "NOISEPAL", "tooltip": "", "type": "1D" }, "108": { "id": 108, "image": ":/image/patterns/FX_108.gif", "name": "SINEWAVE", "tooltip": "", "type": "1D" }, "109": { "id": 109, "image": ":/image/patterns/FX_109.gif", "name": "PHASEDNOISE", "tooltip": "", "type": "1D" }, "11": { "id": 11, "image": ":/image/patterns/FX_011.gif", "name": "DUALSCAN", "tooltip": "", "type": "1D" }, "110": { "id": 110, "image": ":/image/patterns/FX_110.gif", "name": "FLOW", "tooltip": "", "type": "1D" }, "111": { "id": 111, "image": ":/image/patterns/FX_111.gif", "name": "CHUNCHUN", "tooltip": "", "type": "1D" }, "112": { "id": 112, "image": ":/image/patterns/FX_112.gif", "name": "DANCINGSHADOWS", "tooltip": "", "type": "1D" }, "113": { "id": 113, "image": ":/image/patterns/FX_113.gif", "name": "WASHINGMACHINE", "tooltip": "", "type": "1D" }, "114": { "id": 114, "image": ":/image/patterns/FX_114.gif", "name": "", "tooltip": "", "type": "1D" }, "115": { "id": 115, "image": ":/image/patterns/FX_115.gif", "name": "BLENDS", "tooltip": "", "type": "1D" }, "116": { "id": 116, "image": ":/image/patterns/FX_116.gif", "name": "TVSIMULATOR", "tooltip": "", "type": "1D" }, "117": { "id": 117, "image": ":/image/patterns/FX_117.gif", "name": "DYNAMICSMOOTH", "tooltip": "", "type": "1D" }, "118": { "id": 118, "image": ":/image/patterns/FX_118.gif", "name": "SPACESHIPS", "tooltip": "", "type": "2D" }, "119": { "id": 119, "image": ":/image/patterns/FX_119.gif", "name": "CRAZYBEES", "tooltip": "", "type": "2D" }, "12": { "id": 12, "image": ":/image/patterns/FX_012.gif", "name": "FADE", "tooltip": "", "type": "1D" }, "120": { "id": 120, "image": ":/image/patterns/FX_120.gif", "name": "GHOSTRIDER", "tooltip": "", "type": "2D" }, "121": { "id": 121, "image": ":/image/patterns/FX_121.gif", "name": "LOBS", "tooltip": "", "type": "2D" }, "122": { "id": 122, "image": ":/image/patterns/FX_122.gif", "name": "SCROLLname", "tooltip": "", "type": "2D" }, "123": { "id": 123, "image": ":/image/patterns/FX_123.gif", "name": "DRIFTROSE", "tooltip": "", "type": "2D" }, "124": { "id": 124, "image": ":/image/patterns/FX_124.gif", "name": "DISTORTIONWAVES", "tooltip": "", "type": "2D" }, "125": { "id": 125, "image": ":/image/patterns/FX_125.gif", "name": "", "tooltip": "", "type": "SR" }, "126": { "id": 126, "image": ":/image/patterns/FX_126.gif", "name": "", "tooltip": "", "type": "SR" }, "127": { "id": 127, "image": ":/image/patterns/FX_127.gif", "name": "", "tooltip": "", "type": "SR" }, "128": { "id": 128, "image": ":/image/patterns/FX_128.gif", "name": "PIXELS", "tooltip": "", "type": "SR" }, "129": { "id": 129, "image": ":/image/patterns/FX_129.gif", "name": "PIXELWAVE", "tooltip": "", "type": "SR" }, "13": { "id": 13, "image": ":/image/patterns/FX_013.gif", "name": "THEATERCHASE", "tooltip": "", "type": "1D" }, "130": { "id": 130, "image": ":/image/patterns/FX_130.gif", "name": "JUGGLES", "tooltip": "", "type": "SR" } "Pattern": [ ] }
Function :
void Filemanager::initPatternMenu() { QFile file(savePath + folderData + fileJsonPattern); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { FileManagerDebugger.LevelInfo("PATTERNDATA", "Making File", "!"); struct Pattern { int id; QString type, name, image, tooltip; }; QVector<Pattern> patterns = { {0,"1D","SOLID",":/image/patterns/FX_000.gif",""}, {1,"1D","BLINK",":/image/patterns/FX_001.gif",""}, {2,"1D","BREATHE",":/image/patterns/FX_002.gif",""}, {3,"1D","WIPE",":/image/patterns/FX_003.gif",""}, {4,"1D","WIPERANDOM",":/image/patterns/FX_004.gif",""}, {5,"1D","RANDOMCOLORS",":/image/patterns/FX_005.gif",""}, {6,"1D","COLORSWEEP",":/image/patterns/FX_006.gif",""}, {7,"1D","DYNAMIC",":/image/patterns/FX_007.gif",""}, {8,"1D","RAINBOW",":/image/patterns/FX_008.gif",""}, {9,"1D","RAINBOWCYCLE",":/image/patterns/FX_009.gif",""}, {10,"1D","SCAN",":/image/patterns/FX_010.gif",""}, {11,"1D","DUALSCAN",":/image/patterns/FX_011.gif",""}, {12,"1D","FADE",":/image/patterns/FX_012.gif",""}, {13,"1D","THEATERCHASE",":/image/patterns/FX_013.gif",""}, {14,"1D","THEATERCHASERAINBOW",":/image/patterns/FX_014.gif",""}, {15,"1D","RUNNINGLIGHTS",":/image/patterns/FX_015.gif",""}, {16,"1D","SAW",":/image/patterns/FX_016.gif",""}, {17,"1D","TWINKLE",":/image/patterns/FX_017.gif",""}, {18,"1D","DISSOLVE",":/image/patterns/FX_018.gif",""}, {19,"1D","DISSOLVERANDOM",":/image/patterns/FX_019.gif",""}, {20,"1D","SPARKLE",":/image/patterns/FX_020.gif",""}, {21,"1D","SPARKLEFLASH",":/image/patterns/FX_021.gif",""}, {22,"1D","SPARKLEHYPER",":/image/patterns/FX_022.gif",""}, {23,"1D","STROBE",":/image/patterns/FX_023.gif",""}, {24,"1D","STROBERAINBOW",":/image/patterns/FX_024.gif",""}, {25,"1D","STROBEMULTI",":/image/patterns/FX_025.gif",""}, {26,"1D","BLINKRAINBOW",":/image/patterns/FX_026.gif",""}, {27,"1D","ANDROID",":/image/patterns/FX_027.gif",""}, {28,"1D","CHASECOLOR",":/image/patterns/FX_028.gif",""}, {29,"1D","CHASERANDOM",":/image/patterns/FX_029.gif",""}, {30,"1D","CHASERAINBOW",":/image/patterns/FX_030.gif",""}, {31,"1D","CHASEFLASH",":/image/patterns/FX_031.gif",""}, {32,"1D","CHASEFLASHRANDOM",":/image/patterns/FX_032.gif",""}, {33,"1D","CHASERAINBOWWHITE",":/image/patterns/FX_033.gif",""}, {34,"1D","COLORFUL",":/image/patterns/FX_034.gif",""}, {35,"1D","TRAFFICLIGHT",":/image/patterns/FX_035.gif",""}, {36,"1D","COLORSWEEPRANDOM",":/image/patterns/FX_036.gif",""}, {37,"1D","RUNNINGCOLOR",":/image/patterns/FX_037.gif",""}, {38,"1D","AURORA",":/image/patterns/FX_038.gif",""}, {39,"1D","RUNNINGRANDOM",":/image/patterns/FX_039.gif",""}, {40,"1D","LARSONSCANNER",":/image/patterns/FX_040.gif",""}, {41,"1D","COMET",":/image/patterns/FX_041.gif",""}, {42,"1D","FIREWORKS",":/image/patterns/FX_042.gif",""}, {43,"1D","RAIN",":/image/patterns/FX_043.gif",""}, {44,"1D","TETRIX",":/image/patterns/FX_044.gif",""}, {45,"1D","FIREFLICKER",":/image/patterns/FX_045.gif",""}, {46,"1D","GRADIENT",":/image/patterns/FX_046.gif",""}, {47,"1D","LOADING",":/image/patterns/FX_047.gif",""}, {48,"1D","",":/image/patterns/FX_048.gif",""}, {49,"1D","FAIRY",":/image/patterns/FX_049.gif",""}, {50,"1D","TWODOTS",":/image/patterns/FX_050.gif",""}, {51,"1D","FAIRYTWINKLE",":/image/patterns/FX_051.gif",""}, {52,"1D","RUNNINGDUAL",":/image/patterns/FX_052.gif",""}, {53,"1D","",":/image/patterns/FX_053.gif",""}, {54,"1D","TRICOLORCHASE",":/image/patterns/FX_054.gif",""}, {55,"1D","TRICOLORWIPE",":/image/patterns/FX_055.gif",""}, {56,"1D","TRICOLORFADE",":/image/patterns/FX_056.gif",""}, {57,"1D","LIGHTNING",":/image/patterns/FX_057.gif",""}, {58,"1D","ICU",":/image/patterns/FX_058.gif",""}, {59,"1D","MULTICOMET",":/image/patterns/FX_059.gif",""}, {60,"1D","DUALLARSONSCANNER",":/image/patterns/FX_060.gif",""}, {61,"1D","RANDOMCHASE",":/image/patterns/FX_061.gif",""}, {62,"1D","OSCILLATE",":/image/patterns/FX_062.gif",""}, {63,"1D","PRIDE2015",":/image/patterns/FX_063.gif",""}, {64,"1D","JUGGLE",":/image/patterns/FX_064.gif",""}, {65,"1D","PALETTE",":/image/patterns/FX_065.gif",""}, {66,"1D","FIRE2012",":/image/patterns/FX_066.gif",""}, {67,"1D","COLORWAVES",":/image/patterns/FX_067.gif",""}, {68,"1D","BPM",":/image/patterns/FX_068.gif",""}, {69,"1D","FILLNOISE8",":/image/patterns/FX_069.gif",""}, {70,"1D","NOISE161",":/image/patterns/FX_070.gif",""}, {71,"1D","NOISE162",":/image/patterns/FX_071.gif",""}, {72,"1D","NOISE163",":/image/patterns/FX_072.gif",""}, {73,"1D","NOISE164",":/image/patterns/FX_073.gif",""}, {74,"1D","COLORTWINKLE",":/image/patterns/FX_074.gif",""}, {75,"1D","LAKE",":/image/patterns/FX_075.gif",""}, {76,"1D","METEOR",":/image/patterns/FX_076.gif",""}, {77,"1D","METEORSMOOTH",":/image/patterns/FX_077.gif",""}, {78,"1D","RAILWAY",":/image/patterns/FX_078.gif",""}, {79,"1D","RIPPLE",":/image/patterns/FX_079.gif",""}, {80,"1D","TWINKLEFOX",":/image/patterns/FX_080.gif",""}, {81,"1D","TWINKLECAT",":/image/patterns/FX_081.gif",""}, {82,"1D","HALLOWEENEYES",":/image/patterns/FX_082.gif",""}, {83,"1D","STATICPATTERN",":/image/patterns/FX_083.gif",""}, {84,"1D","TRISTATICPATTERN",":/image/patterns/FX_084.gif",""}, {85,"1D","SPOTS",":/image/patterns/FX_085.gif",""}, {86,"1D","SPOTSFADE",":/image/patterns/FX_086.gif",""}, {87,"1D","GLITTER",":/image/patterns/FX_087.gif",""}, {88,"1D","CANDLE",":/image/patterns/FX_088.gif",""}, {89,"1D","STARBURST",":/image/patterns/FX_089.gif",""}, {90,"1D","EXPLODINGFIREWORKS",":/image/patterns/FX_090.gif",""}, {91,"1D","BOUNCINGBALLS",":/image/patterns/FX_091.gif",""}, {92,"1D","SINELON",":/image/patterns/FX_092.gif",""}, {93,"1D","SINELONDUAL",":/image/patterns/FX_093.gif",""}, {94,"1D","SINELONRAINBOW",":/image/patterns/FX_094.gif",""}, {95,"1D","POPCORN",":/image/patterns/FX_095.gif",""}, {96,"1D","DRIP",":/image/patterns/FX_096.gif",""}, {97,"1D","PLASMA",":/image/patterns/FX_097.gif",""}, {98,"1D","PERCENT",":/image/patterns/FX_098.gif",""}, {99,"1D","RIPPLE_RAINBOW",":/image/patterns/FX_099.gif",""}, {100,"1D","HEARTBEAT",":/image/patterns/FX_100.gif",""}, {101,"1D","PACIFICA",":/image/patterns/FX_101.gif",""}, {102,"1D","CANDLEMULTI",":/image/patterns/FX_102.gif",""}, {103,"1D","SOLIDGLITTER",":/image/patterns/FX_103.gif",""}, {104,"1D","SUNRISE",":/image/patterns/FX_104.gif",""}, {105,"1D","PHASED",":/image/patterns/FX_105.gif",""}, {106,"1D","TWINKLEUP",":/image/patterns/FX_106.gif",""}, {107,"1D","NOISEPAL",":/image/patterns/FX_107.gif",""}, {108,"1D","SINEWAVE",":/image/patterns/FX_108.gif",""}, {109,"1D","PHASEDNOISE",":/image/patterns/FX_109.gif",""}, {110,"1D","FLOW",":/image/patterns/FX_110.gif",""}, {111,"1D","CHUNCHUN",":/image/patterns/FX_111.gif",""}, {112,"1D","DANCINGSHADOWS",":/image/patterns/FX_112.gif",""}, {113,"1D","WASHINGMACHINE",":/image/patterns/FX_113.gif",""}, {114,"1D","",":/image/patterns/FX_114.gif",""}, {115,"1D","BLENDS",":/image/patterns/FX_115.gif",""}, {116,"1D","TVSIMULATOR",":/image/patterns/FX_116.gif",""}, {117,"1D","DYNAMICSMOOTH",":/image/patterns/FX_117.gif",""}, {118,"2D","SPACESHIPS",":/image/patterns/FX_118.gif",""}, {119,"2D","CRAZYBEES",":/image/patterns/FX_119.gif",""}, {120,"2D","GHOSTRIDER",":/image/patterns/FX_120.gif",""}, {121,"2D","LOBS",":/image/patterns/FX_121.gif",""}, {122,"2D","SCROLLname",":/image/patterns/FX_122.gif",""}, {123,"2D","DRIFTROSE",":/image/patterns/FX_123.gif",""}, {124,"2D","DISTORTIONWAVES",":/image/patterns/FX_124.gif",""}, {125,"SR","",":/image/patterns/FX_125.gif",""}, {126,"SR","",":/image/patterns/FX_126.gif",""}, {127,"SR","",":/image/patterns/FX_127.gif",""}, {128,"SR","PIXELS",":/image/patterns/FX_128.gif",""}, {129,"SR","PIXELWAVE",":/image/patterns/FX_129.gif",""}, {130,"SR","JUGGLES",":/image/patterns/FX_130.gif",""}, {131,"SR","MATRIPIX",":/image/patterns/FX_131.gif",""}, {132,"SR","GRAVIMETER",":/image/patterns/FX_132.gif",""}, {133,"SR","PLASMOID",":/image/patterns/FX_133.gif",""}, {134,"SR","PUDDLES",":/image/patterns/FX_134.gif",""}, {135,"SR","MIDNOISE",":/image/patterns/FX_135.gif",""}, {136,"SR","NOISEMETER",":/image/patterns/FX_136.gif",""}, {137,"SR","FREQWAVE",":/image/patterns/FX_137.gif",""}, {138,"SR","FREQMATRIX",":/image/patterns/FX_138.gif",""}, {139,"SR 2D","GEQ",":/image/patterns/FX_139.gif",""}, {140,"SR","WATERFALL",":/image/patterns/FX_140.gif",""}, {141,"SR","FREQPIXELS",":/image/patterns/FX_141.gif",""}, {142,"SR","BINMAP",":/image/patterns/FX_142.gif",""}, {143,"SR","NOISEFIRE",":/image/patterns/FX_143.gif",""}, {144,"SR","PUDDLEPEAK",":/image/patterns/FX_144.gif",""}, {145,"SR","NOISEMOVE",":/image/patterns/FX_145.gif",""}, {146,"SR 2D","NOISE",":/image/patterns/FX_146.gif",""}, {147,"SR","PERLINMOVE",":/image/patterns/FX_147.gif",""}, {148,"SR","RIPPLEPEAK",":/image/patterns/FX_148.gif",""}, {149,"SR 2D","FIRENOISE",":/image/patterns/FX_149.gif",""}, {150,"SR 2D","SQUAREDSWIRL",":/image/patterns/FX_150.gif",""}, {151,"SR 2D","FIRE2012",":/image/patterns/FX_151.gif",""}, {152,"SR 2D","DNA",":/image/patterns/FX_152.gif",""}, {153,"SR 2D","MATRIX",":/image/patterns/FX_153.gif",""}, {154,"SR 2D","METABALLS",":/image/patterns/FX_154.gif",""}, {155,"SR","FREQMAP",":/image/patterns/FX_155.gif",""}, {156,"SR","GRAVCENTER",":/image/patterns/FX_156.gif",""}, {157,"SR","GRAVCENTRIC",":/image/patterns/FX_157.gif",""}, {158,"SR","GRAVFREQ",":/image/patterns/FX_158.gif",""}, {159,"SR","DJLIGHT",":/image/patterns/FX_159.gif",""}, {160,"SR 2D","FUNKYPLANK",":/image/patterns/FX_160.gif",""}, {161,"SR 2D","CENTERBARS",":/image/patterns/FX_161.gif",""}, {162,"SR 2D","PULSER",":/image/patterns/FX_162.gif",""}, {163,"SR","BLURZ",":/image/patterns/FX_163.gif",""}, {164,"SR 2D","DRIFT",":/image/patterns/FX_164.gif",""}, {164,"SR 2D","WAVERLY",":/image/patterns/FX_164.gif",""}, {166,"SR 2D","SUNRADIATION",":/image/patterns/FX_166.gif",""}, {167,"SR 2D","COLOREDBURSTS",":/image/patterns/FX_167.gif",""}, {168,"SR 2D","JULIA",":/image/patterns/FX_168.gif",""}, {169,"SR","",":/image/patterns/FX_169.gif",""}, {170,"SR","",":/image/patterns/FX_170.gif",""}, {171,"SR","",":/image/patterns/FX_171.gif",""}, {172,"SR 2D","GAMEOFLIFE",":/image/patterns/FX_172.gif",""}, {173,"SR 2D","TARTAN",":/image/patterns/FX_173.gif",""}, {174,"SR 2D","POLARLIGHTS",":/image/patterns/FX_174.gif",""}, {175,"SR 2D","SWIRL",":/image/patterns/FX_175.gif",""}, {176,"SR 2D","LISSAJOUS",":/image/patterns/FX_176.gif",""}, {177,"SR 2D","FRIZZLES",":/image/patterns/FX_177.gif",""}, {178,"SR 2D","PLASMABALL",":/image/patterns/FX_178.gif",""}, {179,"SR","FLOWSTRIPE",":/image/patterns/FX_179.gif",""}, {180,"SR 2D","HIPHOTIC",":/image/patterns/FX_180.gif",""}, {181,"SR 2D","SINDOTS",":/image/patterns/FX_181.gif",""}, {182,"SR 2D","DNASPIRAL",":/image/patterns/FX_182.gif",""}, {183,"SR 2D","BLACKHOLE",":/image/patterns/FX_183.gif",""}, {184,"SR","WAVESINS",":/image/patterns/FX_184.gif",""}, {185,"SR","ROCKTAVES",":/image/patterns/FX_185.gif",""}, {186,"SR 2D","AKEMI",":/image/patterns/FX_186.gif",""} }; QJsonParseError error; QJsonDocument inputJsonDoc = QJsonDocument::fromJson(file.readAll(), &error); QJsonObject top = inputJsonDoc.object(); QJsonArray patt = top.value( "Pattern" ).toArray(); top.insert("Pattern", patt); for (const auto& pattern : patterns) { QJsonObject patternObject; patternObject.insert("id", pattern.id); patternObject.insert("type", pattern.type); patternObject.insert("name", pattern.name); patternObject.insert("image", pattern.image); patternObject.insert("tooltip", pattern.tooltip); top.insert(QString::number(pattern.id), patternObject); } QJsonDocument outputJsonDoc( top ); file.write(outputJsonDoc.toJson()); file.close(); } }
wrote on 9 Apr 2023, 13:44 last edited by@Kris-Revi as you can see the keys are between brackets: they are strings (as JSON keys ARE strings) and thus are sorted "alphabetically" (if I can call it so). There's absolutely no problem with this.
if you absolutely want your file to be processed in numerical order you should change this line
patternObject.insert("id", pattern.id);
to format the key like "001", "002", "010" etc. But I believe it's useless to waste any time with this.
-
@Kris-Revi as you can see the keys are between brackets: they are strings (as JSON keys ARE strings) and thus are sorted "alphabetically" (if I can call it so). There's absolutely no problem with this.
if you absolutely want your file to be processed in numerical order you should change this line
patternObject.insert("id", pattern.id);
to format the key like "001", "002", "010" etc. But I believe it's useless to waste any time with this.
wrote on 9 Apr 2023, 13:52 last edited by@ankou29666 scroll down to the bottom of the json file,
"Pattern": []
is at the bottomit should be
{ "Pattern": [ "0": { "id": 0, "image": ":/image/patterns/FX_000.gif", "name": "SOLID", "tooltip": "", "type": "1D" }, "1": { "id": 1, "image": ":/image/patterns/FX_001.gif", "name": "BLINK", "tooltip": "", "type": "1D" } ] }
-
my problem is that the json that gets written to the json file is wrong
As you can see first off
"Pattern": []
is at the bottom for some reason and second if you start at the the top it starts at ID 0,1 then suddenly 10 and then suddenly 100now i know im doing something wrong but atm i cannot see what, why and where! please help me!
{ "0": { "id": 0, "image": ":/image/patterns/FX_000.gif", "name": "SOLID", "tooltip": "", "type": "1D" }, "1": { "id": 1, "image": ":/image/patterns/FX_001.gif", "name": "BLINK", "tooltip": "", "type": "1D" }, "10": { "id": 10, "image": ":/image/patterns/FX_010.gif", "name": "SCAN", "tooltip": "", "type": "1D" }, "100": { "id": 100, "image": ":/image/patterns/FX_100.gif", "name": "HEARTBEAT", "tooltip": "", "type": "1D" }, "101": { "id": 101, "image": ":/image/patterns/FX_101.gif", "name": "PACIFICA", "tooltip": "", "type": "1D" }, "102": { "id": 102, "image": ":/image/patterns/FX_102.gif", "name": "CANDLEMULTI", "tooltip": "", "type": "1D" }, "103": { "id": 103, "image": ":/image/patterns/FX_103.gif", "name": "SOLIDGLITTER", "tooltip": "", "type": "1D" }, "104": { "id": 104, "image": ":/image/patterns/FX_104.gif", "name": "SUNRISE", "tooltip": "", "type": "1D" }, "105": { "id": 105, "image": ":/image/patterns/FX_105.gif", "name": "PHASED", "tooltip": "", "type": "1D" }, "106": { "id": 106, "image": ":/image/patterns/FX_106.gif", "name": "TWINKLEUP", "tooltip": "", "type": "1D" }, "107": { "id": 107, "image": ":/image/patterns/FX_107.gif", "name": "NOISEPAL", "tooltip": "", "type": "1D" }, "108": { "id": 108, "image": ":/image/patterns/FX_108.gif", "name": "SINEWAVE", "tooltip": "", "type": "1D" }, "109": { "id": 109, "image": ":/image/patterns/FX_109.gif", "name": "PHASEDNOISE", "tooltip": "", "type": "1D" }, "11": { "id": 11, "image": ":/image/patterns/FX_011.gif", "name": "DUALSCAN", "tooltip": "", "type": "1D" }, "110": { "id": 110, "image": ":/image/patterns/FX_110.gif", "name": "FLOW", "tooltip": "", "type": "1D" }, "111": { "id": 111, "image": ":/image/patterns/FX_111.gif", "name": "CHUNCHUN", "tooltip": "", "type": "1D" }, "112": { "id": 112, "image": ":/image/patterns/FX_112.gif", "name": "DANCINGSHADOWS", "tooltip": "", "type": "1D" }, "113": { "id": 113, "image": ":/image/patterns/FX_113.gif", "name": "WASHINGMACHINE", "tooltip": "", "type": "1D" }, "114": { "id": 114, "image": ":/image/patterns/FX_114.gif", "name": "", "tooltip": "", "type": "1D" }, "115": { "id": 115, "image": ":/image/patterns/FX_115.gif", "name": "BLENDS", "tooltip": "", "type": "1D" }, "116": { "id": 116, "image": ":/image/patterns/FX_116.gif", "name": "TVSIMULATOR", "tooltip": "", "type": "1D" }, "117": { "id": 117, "image": ":/image/patterns/FX_117.gif", "name": "DYNAMICSMOOTH", "tooltip": "", "type": "1D" }, "118": { "id": 118, "image": ":/image/patterns/FX_118.gif", "name": "SPACESHIPS", "tooltip": "", "type": "2D" }, "119": { "id": 119, "image": ":/image/patterns/FX_119.gif", "name": "CRAZYBEES", "tooltip": "", "type": "2D" }, "12": { "id": 12, "image": ":/image/patterns/FX_012.gif", "name": "FADE", "tooltip": "", "type": "1D" }, "120": { "id": 120, "image": ":/image/patterns/FX_120.gif", "name": "GHOSTRIDER", "tooltip": "", "type": "2D" }, "121": { "id": 121, "image": ":/image/patterns/FX_121.gif", "name": "LOBS", "tooltip": "", "type": "2D" }, "122": { "id": 122, "image": ":/image/patterns/FX_122.gif", "name": "SCROLLname", "tooltip": "", "type": "2D" }, "123": { "id": 123, "image": ":/image/patterns/FX_123.gif", "name": "DRIFTROSE", "tooltip": "", "type": "2D" }, "124": { "id": 124, "image": ":/image/patterns/FX_124.gif", "name": "DISTORTIONWAVES", "tooltip": "", "type": "2D" }, "125": { "id": 125, "image": ":/image/patterns/FX_125.gif", "name": "", "tooltip": "", "type": "SR" }, "126": { "id": 126, "image": ":/image/patterns/FX_126.gif", "name": "", "tooltip": "", "type": "SR" }, "127": { "id": 127, "image": ":/image/patterns/FX_127.gif", "name": "", "tooltip": "", "type": "SR" }, "128": { "id": 128, "image": ":/image/patterns/FX_128.gif", "name": "PIXELS", "tooltip": "", "type": "SR" }, "129": { "id": 129, "image": ":/image/patterns/FX_129.gif", "name": "PIXELWAVE", "tooltip": "", "type": "SR" }, "13": { "id": 13, "image": ":/image/patterns/FX_013.gif", "name": "THEATERCHASE", "tooltip": "", "type": "1D" }, "130": { "id": 130, "image": ":/image/patterns/FX_130.gif", "name": "JUGGLES", "tooltip": "", "type": "SR" } "Pattern": [ ] }
Function :
void Filemanager::initPatternMenu() { QFile file(savePath + folderData + fileJsonPattern); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { FileManagerDebugger.LevelInfo("PATTERNDATA", "Making File", "!"); struct Pattern { int id; QString type, name, image, tooltip; }; QVector<Pattern> patterns = { {0,"1D","SOLID",":/image/patterns/FX_000.gif",""}, {1,"1D","BLINK",":/image/patterns/FX_001.gif",""}, {2,"1D","BREATHE",":/image/patterns/FX_002.gif",""}, {3,"1D","WIPE",":/image/patterns/FX_003.gif",""}, {4,"1D","WIPERANDOM",":/image/patterns/FX_004.gif",""}, {5,"1D","RANDOMCOLORS",":/image/patterns/FX_005.gif",""}, {6,"1D","COLORSWEEP",":/image/patterns/FX_006.gif",""}, {7,"1D","DYNAMIC",":/image/patterns/FX_007.gif",""}, {8,"1D","RAINBOW",":/image/patterns/FX_008.gif",""}, {9,"1D","RAINBOWCYCLE",":/image/patterns/FX_009.gif",""}, {10,"1D","SCAN",":/image/patterns/FX_010.gif",""}, {11,"1D","DUALSCAN",":/image/patterns/FX_011.gif",""}, {12,"1D","FADE",":/image/patterns/FX_012.gif",""}, {13,"1D","THEATERCHASE",":/image/patterns/FX_013.gif",""}, {14,"1D","THEATERCHASERAINBOW",":/image/patterns/FX_014.gif",""}, {15,"1D","RUNNINGLIGHTS",":/image/patterns/FX_015.gif",""}, {16,"1D","SAW",":/image/patterns/FX_016.gif",""}, {17,"1D","TWINKLE",":/image/patterns/FX_017.gif",""}, {18,"1D","DISSOLVE",":/image/patterns/FX_018.gif",""}, {19,"1D","DISSOLVERANDOM",":/image/patterns/FX_019.gif",""}, {20,"1D","SPARKLE",":/image/patterns/FX_020.gif",""}, {21,"1D","SPARKLEFLASH",":/image/patterns/FX_021.gif",""}, {22,"1D","SPARKLEHYPER",":/image/patterns/FX_022.gif",""}, {23,"1D","STROBE",":/image/patterns/FX_023.gif",""}, {24,"1D","STROBERAINBOW",":/image/patterns/FX_024.gif",""}, {25,"1D","STROBEMULTI",":/image/patterns/FX_025.gif",""}, {26,"1D","BLINKRAINBOW",":/image/patterns/FX_026.gif",""}, {27,"1D","ANDROID",":/image/patterns/FX_027.gif",""}, {28,"1D","CHASECOLOR",":/image/patterns/FX_028.gif",""}, {29,"1D","CHASERANDOM",":/image/patterns/FX_029.gif",""}, {30,"1D","CHASERAINBOW",":/image/patterns/FX_030.gif",""}, {31,"1D","CHASEFLASH",":/image/patterns/FX_031.gif",""}, {32,"1D","CHASEFLASHRANDOM",":/image/patterns/FX_032.gif",""}, {33,"1D","CHASERAINBOWWHITE",":/image/patterns/FX_033.gif",""}, {34,"1D","COLORFUL",":/image/patterns/FX_034.gif",""}, {35,"1D","TRAFFICLIGHT",":/image/patterns/FX_035.gif",""}, {36,"1D","COLORSWEEPRANDOM",":/image/patterns/FX_036.gif",""}, {37,"1D","RUNNINGCOLOR",":/image/patterns/FX_037.gif",""}, {38,"1D","AURORA",":/image/patterns/FX_038.gif",""}, {39,"1D","RUNNINGRANDOM",":/image/patterns/FX_039.gif",""}, {40,"1D","LARSONSCANNER",":/image/patterns/FX_040.gif",""}, {41,"1D","COMET",":/image/patterns/FX_041.gif",""}, {42,"1D","FIREWORKS",":/image/patterns/FX_042.gif",""}, {43,"1D","RAIN",":/image/patterns/FX_043.gif",""}, {44,"1D","TETRIX",":/image/patterns/FX_044.gif",""}, {45,"1D","FIREFLICKER",":/image/patterns/FX_045.gif",""}, {46,"1D","GRADIENT",":/image/patterns/FX_046.gif",""}, {47,"1D","LOADING",":/image/patterns/FX_047.gif",""}, {48,"1D","",":/image/patterns/FX_048.gif",""}, {49,"1D","FAIRY",":/image/patterns/FX_049.gif",""}, {50,"1D","TWODOTS",":/image/patterns/FX_050.gif",""}, {51,"1D","FAIRYTWINKLE",":/image/patterns/FX_051.gif",""}, {52,"1D","RUNNINGDUAL",":/image/patterns/FX_052.gif",""}, {53,"1D","",":/image/patterns/FX_053.gif",""}, {54,"1D","TRICOLORCHASE",":/image/patterns/FX_054.gif",""}, {55,"1D","TRICOLORWIPE",":/image/patterns/FX_055.gif",""}, {56,"1D","TRICOLORFADE",":/image/patterns/FX_056.gif",""}, {57,"1D","LIGHTNING",":/image/patterns/FX_057.gif",""}, {58,"1D","ICU",":/image/patterns/FX_058.gif",""}, {59,"1D","MULTICOMET",":/image/patterns/FX_059.gif",""}, {60,"1D","DUALLARSONSCANNER",":/image/patterns/FX_060.gif",""}, {61,"1D","RANDOMCHASE",":/image/patterns/FX_061.gif",""}, {62,"1D","OSCILLATE",":/image/patterns/FX_062.gif",""}, {63,"1D","PRIDE2015",":/image/patterns/FX_063.gif",""}, {64,"1D","JUGGLE",":/image/patterns/FX_064.gif",""}, {65,"1D","PALETTE",":/image/patterns/FX_065.gif",""}, {66,"1D","FIRE2012",":/image/patterns/FX_066.gif",""}, {67,"1D","COLORWAVES",":/image/patterns/FX_067.gif",""}, {68,"1D","BPM",":/image/patterns/FX_068.gif",""}, {69,"1D","FILLNOISE8",":/image/patterns/FX_069.gif",""}, {70,"1D","NOISE161",":/image/patterns/FX_070.gif",""}, {71,"1D","NOISE162",":/image/patterns/FX_071.gif",""}, {72,"1D","NOISE163",":/image/patterns/FX_072.gif",""}, {73,"1D","NOISE164",":/image/patterns/FX_073.gif",""}, {74,"1D","COLORTWINKLE",":/image/patterns/FX_074.gif",""}, {75,"1D","LAKE",":/image/patterns/FX_075.gif",""}, {76,"1D","METEOR",":/image/patterns/FX_076.gif",""}, {77,"1D","METEORSMOOTH",":/image/patterns/FX_077.gif",""}, {78,"1D","RAILWAY",":/image/patterns/FX_078.gif",""}, {79,"1D","RIPPLE",":/image/patterns/FX_079.gif",""}, {80,"1D","TWINKLEFOX",":/image/patterns/FX_080.gif",""}, {81,"1D","TWINKLECAT",":/image/patterns/FX_081.gif",""}, {82,"1D","HALLOWEENEYES",":/image/patterns/FX_082.gif",""}, {83,"1D","STATICPATTERN",":/image/patterns/FX_083.gif",""}, {84,"1D","TRISTATICPATTERN",":/image/patterns/FX_084.gif",""}, {85,"1D","SPOTS",":/image/patterns/FX_085.gif",""}, {86,"1D","SPOTSFADE",":/image/patterns/FX_086.gif",""}, {87,"1D","GLITTER",":/image/patterns/FX_087.gif",""}, {88,"1D","CANDLE",":/image/patterns/FX_088.gif",""}, {89,"1D","STARBURST",":/image/patterns/FX_089.gif",""}, {90,"1D","EXPLODINGFIREWORKS",":/image/patterns/FX_090.gif",""}, {91,"1D","BOUNCINGBALLS",":/image/patterns/FX_091.gif",""}, {92,"1D","SINELON",":/image/patterns/FX_092.gif",""}, {93,"1D","SINELONDUAL",":/image/patterns/FX_093.gif",""}, {94,"1D","SINELONRAINBOW",":/image/patterns/FX_094.gif",""}, {95,"1D","POPCORN",":/image/patterns/FX_095.gif",""}, {96,"1D","DRIP",":/image/patterns/FX_096.gif",""}, {97,"1D","PLASMA",":/image/patterns/FX_097.gif",""}, {98,"1D","PERCENT",":/image/patterns/FX_098.gif",""}, {99,"1D","RIPPLE_RAINBOW",":/image/patterns/FX_099.gif",""}, {100,"1D","HEARTBEAT",":/image/patterns/FX_100.gif",""}, {101,"1D","PACIFICA",":/image/patterns/FX_101.gif",""}, {102,"1D","CANDLEMULTI",":/image/patterns/FX_102.gif",""}, {103,"1D","SOLIDGLITTER",":/image/patterns/FX_103.gif",""}, {104,"1D","SUNRISE",":/image/patterns/FX_104.gif",""}, {105,"1D","PHASED",":/image/patterns/FX_105.gif",""}, {106,"1D","TWINKLEUP",":/image/patterns/FX_106.gif",""}, {107,"1D","NOISEPAL",":/image/patterns/FX_107.gif",""}, {108,"1D","SINEWAVE",":/image/patterns/FX_108.gif",""}, {109,"1D","PHASEDNOISE",":/image/patterns/FX_109.gif",""}, {110,"1D","FLOW",":/image/patterns/FX_110.gif",""}, {111,"1D","CHUNCHUN",":/image/patterns/FX_111.gif",""}, {112,"1D","DANCINGSHADOWS",":/image/patterns/FX_112.gif",""}, {113,"1D","WASHINGMACHINE",":/image/patterns/FX_113.gif",""}, {114,"1D","",":/image/patterns/FX_114.gif",""}, {115,"1D","BLENDS",":/image/patterns/FX_115.gif",""}, {116,"1D","TVSIMULATOR",":/image/patterns/FX_116.gif",""}, {117,"1D","DYNAMICSMOOTH",":/image/patterns/FX_117.gif",""}, {118,"2D","SPACESHIPS",":/image/patterns/FX_118.gif",""}, {119,"2D","CRAZYBEES",":/image/patterns/FX_119.gif",""}, {120,"2D","GHOSTRIDER",":/image/patterns/FX_120.gif",""}, {121,"2D","LOBS",":/image/patterns/FX_121.gif",""}, {122,"2D","SCROLLname",":/image/patterns/FX_122.gif",""}, {123,"2D","DRIFTROSE",":/image/patterns/FX_123.gif",""}, {124,"2D","DISTORTIONWAVES",":/image/patterns/FX_124.gif",""}, {125,"SR","",":/image/patterns/FX_125.gif",""}, {126,"SR","",":/image/patterns/FX_126.gif",""}, {127,"SR","",":/image/patterns/FX_127.gif",""}, {128,"SR","PIXELS",":/image/patterns/FX_128.gif",""}, {129,"SR","PIXELWAVE",":/image/patterns/FX_129.gif",""}, {130,"SR","JUGGLES",":/image/patterns/FX_130.gif",""}, {131,"SR","MATRIPIX",":/image/patterns/FX_131.gif",""}, {132,"SR","GRAVIMETER",":/image/patterns/FX_132.gif",""}, {133,"SR","PLASMOID",":/image/patterns/FX_133.gif",""}, {134,"SR","PUDDLES",":/image/patterns/FX_134.gif",""}, {135,"SR","MIDNOISE",":/image/patterns/FX_135.gif",""}, {136,"SR","NOISEMETER",":/image/patterns/FX_136.gif",""}, {137,"SR","FREQWAVE",":/image/patterns/FX_137.gif",""}, {138,"SR","FREQMATRIX",":/image/patterns/FX_138.gif",""}, {139,"SR 2D","GEQ",":/image/patterns/FX_139.gif",""}, {140,"SR","WATERFALL",":/image/patterns/FX_140.gif",""}, {141,"SR","FREQPIXELS",":/image/patterns/FX_141.gif",""}, {142,"SR","BINMAP",":/image/patterns/FX_142.gif",""}, {143,"SR","NOISEFIRE",":/image/patterns/FX_143.gif",""}, {144,"SR","PUDDLEPEAK",":/image/patterns/FX_144.gif",""}, {145,"SR","NOISEMOVE",":/image/patterns/FX_145.gif",""}, {146,"SR 2D","NOISE",":/image/patterns/FX_146.gif",""}, {147,"SR","PERLINMOVE",":/image/patterns/FX_147.gif",""}, {148,"SR","RIPPLEPEAK",":/image/patterns/FX_148.gif",""}, {149,"SR 2D","FIRENOISE",":/image/patterns/FX_149.gif",""}, {150,"SR 2D","SQUAREDSWIRL",":/image/patterns/FX_150.gif",""}, {151,"SR 2D","FIRE2012",":/image/patterns/FX_151.gif",""}, {152,"SR 2D","DNA",":/image/patterns/FX_152.gif",""}, {153,"SR 2D","MATRIX",":/image/patterns/FX_153.gif",""}, {154,"SR 2D","METABALLS",":/image/patterns/FX_154.gif",""}, {155,"SR","FREQMAP",":/image/patterns/FX_155.gif",""}, {156,"SR","GRAVCENTER",":/image/patterns/FX_156.gif",""}, {157,"SR","GRAVCENTRIC",":/image/patterns/FX_157.gif",""}, {158,"SR","GRAVFREQ",":/image/patterns/FX_158.gif",""}, {159,"SR","DJLIGHT",":/image/patterns/FX_159.gif",""}, {160,"SR 2D","FUNKYPLANK",":/image/patterns/FX_160.gif",""}, {161,"SR 2D","CENTERBARS",":/image/patterns/FX_161.gif",""}, {162,"SR 2D","PULSER",":/image/patterns/FX_162.gif",""}, {163,"SR","BLURZ",":/image/patterns/FX_163.gif",""}, {164,"SR 2D","DRIFT",":/image/patterns/FX_164.gif",""}, {164,"SR 2D","WAVERLY",":/image/patterns/FX_164.gif",""}, {166,"SR 2D","SUNRADIATION",":/image/patterns/FX_166.gif",""}, {167,"SR 2D","COLOREDBURSTS",":/image/patterns/FX_167.gif",""}, {168,"SR 2D","JULIA",":/image/patterns/FX_168.gif",""}, {169,"SR","",":/image/patterns/FX_169.gif",""}, {170,"SR","",":/image/patterns/FX_170.gif",""}, {171,"SR","",":/image/patterns/FX_171.gif",""}, {172,"SR 2D","GAMEOFLIFE",":/image/patterns/FX_172.gif",""}, {173,"SR 2D","TARTAN",":/image/patterns/FX_173.gif",""}, {174,"SR 2D","POLARLIGHTS",":/image/patterns/FX_174.gif",""}, {175,"SR 2D","SWIRL",":/image/patterns/FX_175.gif",""}, {176,"SR 2D","LISSAJOUS",":/image/patterns/FX_176.gif",""}, {177,"SR 2D","FRIZZLES",":/image/patterns/FX_177.gif",""}, {178,"SR 2D","PLASMABALL",":/image/patterns/FX_178.gif",""}, {179,"SR","FLOWSTRIPE",":/image/patterns/FX_179.gif",""}, {180,"SR 2D","HIPHOTIC",":/image/patterns/FX_180.gif",""}, {181,"SR 2D","SINDOTS",":/image/patterns/FX_181.gif",""}, {182,"SR 2D","DNASPIRAL",":/image/patterns/FX_182.gif",""}, {183,"SR 2D","BLACKHOLE",":/image/patterns/FX_183.gif",""}, {184,"SR","WAVESINS",":/image/patterns/FX_184.gif",""}, {185,"SR","ROCKTAVES",":/image/patterns/FX_185.gif",""}, {186,"SR 2D","AKEMI",":/image/patterns/FX_186.gif",""} }; QJsonParseError error; QJsonDocument inputJsonDoc = QJsonDocument::fromJson(file.readAll(), &error); QJsonObject top = inputJsonDoc.object(); QJsonArray patt = top.value( "Pattern" ).toArray(); top.insert("Pattern", patt); for (const auto& pattern : patterns) { QJsonObject patternObject; patternObject.insert("id", pattern.id); patternObject.insert("type", pattern.type); patternObject.insert("name", pattern.name); patternObject.insert("image", pattern.image); patternObject.insert("tooltip", pattern.tooltip); top.insert(QString::number(pattern.id), patternObject); } QJsonDocument outputJsonDoc( top ); file.write(outputJsonDoc.toJson()); file.close(); } }
wrote on 9 Apr 2023, 16:02 last edited by A Former User 4 Sept 2023, 16:10@Kris-Revi said in Writing to json file, output wrong!:
scroll down to the bottom of the json file, "Pattern": [] is at the bottom
sorry misread it. You simply insert at the wrong place (at the top instead of inside the pattern), in that case what you need is simply
patt.insert(QString::number(pattern.id), patternObject); // instead of // top.insert(QString::number(pattern.id), patternObject);
by the way, this JSON is wrong, you will never gonna succeed :
@Kris-Revi said in Writing to json file, output wrong!:it should be
{
"Pattern": [
"0": {
"id": 0,
"image": ":/image/patterns/FX_000.gif",
"name": "SOLID",
"tooltip": "",
"type": "1D"
},
"1": {
"id": 1,
"image": ":/image/patterns/FX_001.gif",
"name": "BLINK",
"tooltip": "",
"type": "1D"
}
]
}either you keep pattern as an array of objects :
{ pattern: [ { "id": 0, "name": "SOLID" }, { "id": 1, "name": "BLINK" } ] }
and access them by numeric index
or you change it to an object :
{ pattern: { "0" : { "id": 0, "name": "SOLID" }, "1": { "id": 1, "name": "BLINK" } ] }
and use string index
-
wrote on 9 Apr 2023, 16:38 last edited by
i fixed it by myself
QJsonParseError error; QJsonDocument inputJsonDoc = QJsonDocument::fromJson(file.readAll(), &error); QJsonObject top = inputJsonDoc.object(); QJsonArray patt = top.value( "Pattern" ).toArray(); for (const auto& pattern : patterns) { QJsonObject patternObject; patternObject.insert("id", pattern.id); patternObject.insert("type", pattern.type); patternObject.insert("name", pattern.name); patternObject.insert("image", pattern.image); patternObject.insert("tooltip", pattern.tooltip); patt.append(patternObject); } top.insert("Pattern", patt); QJsonDocument outputJsonDoc( top ); file.write(outputJsonDoc.toJson()); file.close(); }
-
1/5