Solved How much memory to allow for a 30 character string?
Guerrian last edited by Guerrian
I see that sizeof returns 8 for a QString:
QString s; s = "012345678901234567890123456789"; qDebug() << sizeof(s);
How much more memory is taken up by the characters, is it 1 byte per character?
sizeof return the size of an object:
qDebug() << sizeof(QString); // -> 8
A QString is composed of 16 bits unicode characters.
Hence the size in memory is equal to:
2*s.size() or sizeof(QChar)*s.size();
SGaist Lifetime Qt Champion last edited by
@Guerrian out of curiosity, are you only interested in the space taken by the chars or the complete data structure that is QString ?