0
I am new using Qt Creator and am currently working on a project for college and am getting the following error
ASSERT Failure in Qlist::Operator[]: "index out of range", file .. /.. /. /.. /Qt485/imx28/Qt-Everywhere-opensource-src-4.8.5/include/Qtcore/.. /.. /src/corelib/tools/qlist. h, line 477
excerpt from the QT Code
void page100::processarDados(){
QString json = reply->readAll();
QRegExp expretion("[{}]"); //expreçao regular
QStringList Attribute;
Attribute = json.split(expretion);
QStringList elementRecord;
QRegExp exp("[:,]"); //expreçao regular
for(int i = 1; i< Attribute.size();i+=2){
elementRecord = Attribute[i].split(exp);
for(int j = 0; j <elementRecord.size(); j++){
elementRecord = Attribute[i].split(exp);
qDebug() << elementRecord[j];
}
}
}
Json that is being received
[
{
"idInstallation": 0,
"project_Code": 0,
"runId": 4,
"block": "RUN_1",
"input": "PLC_DigIn_1",
"state": "1",
"operation": true,
"allDescription": null,
"reducedDescription": "Test",
"tstId": 0
},
{
"idInstallation": 0,
"project_Code": 0,
"runId": 5,
"block": "RUN_2",
"input": "PLC_DigIn_2",
"state": "1",
"operation": true,
"allDescription": null,
"reducedDescription": "Test 2",
"tstId": 0
},
{
"idInstallation": 0,
"project_Code": 0,
"runId": 8,
"block": "RUN_3",
"input": "PLC_DigIn_3",
"state": "1",
"operation": true,
"allDescription": null,
"reducedDescription": "Test 3",
"tstId": 0
}
]
in the first for I am going through 2-in-2 to ignore the commas that exist between each record in my json
the error is giving in the second for, where in each record I go through all the elements EX: in record 1
- elementRecord[0] = "idInstallation"
- elementRecord1 = 0
- elementRecord[2] = "project_Code"
- elementRecord[3] = 0
- elementRecord[4] = "runId"
- elementRecord[5] = 4
- elementRecord[6] = "block"
- elementRecord[7] = "RUN_1"
- elementRecord[8] = "input"
- elementRecord[9] = "Plc_digin_1"
- elementRecord[10] = "state"
- elementRecord[11] = "1"
- elementRecord[12] = "Operation"
- elementRecord[13] = true
- elementRecord[14] = "allDescription"
- elementRecord[15] = null
- elementRecord[16] = "reducedDescription"
- elementRecord[17] = "Test"
- elementRecord[18] = "tstId"
- elementRecord[19] = 0
and so on to all other records.
but I can’t identify the error. someone could help me ?
Transcribe the json you’re getting straight to the question.
– Boneco Sinforoso
Can you explain in words what you’re trying to do with those regular expressions ?
– Isac
@Isac sorry for the lack of information in the question, I’m using Qt4.8 and I don’t have support for working with Json, one way out was to treat this Json as String. I’m using regular expressions to create subStrings.
– Gabriel Silva