Qt Error: ASSERT Failure in Qlist<T>

Asked

Viewed 58 times

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.

  • Can you explain in words what you’re trying to do with those regular expressions ?

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

1 answer

1


The error indicates that the selected index "does not exist" within the array:

index out of range

But I am responding not for this, but simply because it makes no sense to use regular expression for a JSON parse, I understand that Qt4.8 does not have support for Json, something that is only supported in Qt5: https://doc.qt.io/qt-5/json.html

However there are solutions, such as:

  • http://qjson.sourceforge.net

    This needs to be compiled before "linking"

  • https://github.com/eteran/qjson4

    This works similar to the Qt5 API, which would make it easier in a port for new versions of Qt5

  • Most likely solution, migrate to Qt5

    I imagine you must have installed Qt4 because it comes in the repositories, but if you choose to use Qt5 (or the eteran/qjson4) you can do so:

    QString json = reply->readAll();
    
    QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8(), &error);
    
    if (error == QJsonParseError::NoError) {
         //Se o parse funcionar
    } else {
         qDebug() << error.errorString();
    }
    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.