Seite 1 von 1

QByteArray.split() returning QList with empty first element

Verfasst: 4. Februar 2015 12:46
von Freddy_Kay
Hey Guys,

I got a QByteArray containing some data. I distinguish different kinds of data via key characters which I prepend with a '&' character. Currently the data QByteArray only contians something like this: data = "&t02.04.2014".

Code: Alles auswählen

void foo(QByteArray data){
 
     QList<QByteArray> cmdList = data.split('&');
 
     if(cmdList.size() != data.count('&')) dispError("Command List size != number of '&'");
     //At this point the cmdList contains 2 elments where the first one is empty (presuming the data array is like noted above. 
 
     //do fancy stuff with the data
}
I don't quite understand why there are two elments in the QList as I am only expecting one.

Re: QByteArray.split() returning QList with empty first elem

Verfasst: 4. Februar 2015 18:27
von Christian81
Because the first on is an empty part when you split at '&'. Therefore at least QString has an argument to split():
QString::KeepEmptyParts 0 If a field is empty, keep it in the result.
QString::SkipEmptyParts 1 If a field is empty, don't include it in the result.

Re: QByteArray.split() returning QList with empty first elem

Verfasst: 4. Februar 2015 20:37
von Freddy_Kay
Christian81 hat geschrieben:Because the first on is an empty part when you split at '&'. Therefore at least QString has an argument to split():
QString::KeepEmptyParts 0 If a field is empty, keep it in the result.
QString::SkipEmptyParts 1 If a field is empty, don't include it in the result.
ich seh grad. das ist ja nen deutsches forum...

Danke dir. Macht jetzt sinn.