Hány bájt egy QString?

Fórumok

Hellosztok!

Olyan gondban vagyok, hogy sok QStringel kell dolgoznom és hogy tudom megmérni a méretét? Mert:

std::cout << sizeof(QString) << std::endl; // 4
QString tmp = "Ez egy qstring."
std::cout << sizeof(tmp) << std::endl; // 4

Hol az igazság?

Hozzászólások

tmp.size() a mérete karakterben (QChar), ha byte-ban kell, akkor *2

Remélem ez az, amit keresel:

In the output, we can see that sizeof(qstring) is only 4 bytes, but it is a complex class that uses dynamic memory, so we must call length() to get the number of QChar in the string. Since a QChar is twice the sizeof(char), we need to double the length to compute the actual size of qstring in memory. Under the covers, QString shares memory with other strings that have the same value, so after a copy, the dynamic memory does not 'belong' exclusively to one QString object.

http://cartan.cas.suffolk.edu/oopdocbook/html/simpletypes.html

--
A gyors gondolat többet ér, mint a gyors mozdulat.