2016-04-15 27 views
0

Ich habe eine XML-Datei in einem QByteArray Ich benutze die indexOf-Methode, um eine Zeichenfolge im Array zu finden, aber die zurückgegebene Position ist nicht korrekt. Wenn ich den Dateninhalt mit qDebug überprüfe, kann ich sehen, dass die Daten Escape-Zeichen haben, was kein Problem ist, aber ich denke nicht, dass indexOf die Escape-Zeichen zählt.Qt5.5 QByteArray indexOf mittleres falsches Ergebnis

Zum Beispiel das Ergebnis aus:

qDebug() << arybytXML; 

Ein Ausschnitt aus dem Ergebnis ist folgendes:

<?xml version="1.0" encoding="utf-8"?><!--\n Node:   gui\n Attrbuttes: left, right, top and bottom defines the pixel white space to allow\n    from the edge of the display\n\t\tlanguage, should be set to the appropriate country code, an XML file named using\n\t\tthe country code must exist, e.g. 44.xml\n//-->\n<gui id=\"root\" bottom=\"0\" left=\"0\" right=\"0\" top=\"24\" language=\"44\"> 

Ich verwende den Code:

intOpenComment = arybytXML.indexOf("<!--"); 

Das Ergebnis ist, dass intOpenComment ist 39. Wenn ich dann nach dem Ende-Kommentar suche und versuche, die Daten zu extrahieren, bekomme ich ein falsches Ergebnis:

intClosingComment = arybytXML.indexOf("-->", intOpenComment); 

    QString strComment = arybytXML.mid(intOpenComment 
             ,intClosingComment + strlen("-->")); 

Ergebnis:

<!--\n Node:   gui\n Attrbuttes: left, right, top and bottom defines the pixel white space to allow\n    from the edge of the display\n\t\tlanguage, should be set to the appropriate country code, an XML file named using\n\t\tthe country code must exist, e.g. 44.xml\n//-->\n<gui id=\"root\" bottom=\"0\" left=\"0\" rig" 

Das Ergebnis stoppt nach sollte ->, warum mehr Daten gibt es?

Antwort

0

Das Problem ist, dass bei Verwendung von Mitte, sollte der 2. Parameter die Anzahl der Bytes sein und benötigt, um 'intOpenComment' entfernt haben.