PDA

View Full Version : inver data from QByteArray



aj2903
16th January 2010, 06:31
hii...
I'm reading file & stroing it in QBYteArray.
The question is :
How can we invert data stored in QByteArray ?

thanks in advanced

kichi
16th January 2010, 07:50
If the copying is allowable, one of solution is as follows.



QByteArray cstring("Qt is cross platform C++ application framework.");
const int charCount = cstring.count();
qDebug() << cstring;

QByteArray invertedCString;
invertedCString.resize(charCount);
for(int i = 0; i < cstring.count(); ++i) {
invertedCString[i] = cstring.at(charCount - 1 - i);
}
qDebug() << invertedCString;


if your string is multi bytes string, you can use QString instead.

kichi
16th January 2010, 07:56
for(int i = 0; i < cstring.count(); ++i) {


I'm sorry, I modified the code.



for(int i = 0; i < charCount; ++i) {