Qt6 topics merged with General

How much memory to allow for a 30 character string?

  • 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?

  • Hi,

    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:


  • Lifetime Qt Champion


    @Guerrian out of curiosity, are you only interested in the space taken by the chars or the complete data structure that is QString ?

Log in to reply