[Qt-interest] QString and UNICODE: size determination

Bob Hood bhood2 at comcast.net
Wed Jul 8 18:16:15 CEST 2009


I want to verify that this is the best way to do this.  If there's a
better way, please feel free to correct me.

I'm using a QString to store data that I'm going to use with direct
Windows API calls in my Qt application.  I'm setting/clearing a Windows
Registry key.  The call to these functions requires a wchar_t* and a
size.  QString returns a size(), but it is only returning the number of
characters in the string, not the actual number of bytes that are
consumed by the string.

In order to determine this, I'm making an assumption that the size()
value can be multiplied by a factor of 2 in order to get the correct
length.  For example:

    [...]
        int len = path_str.size();
    #ifdef UNICODE
        len *= 2;
    #endif
        RegSetValueEx(hkey,label_str.utf16(),0,REG_SZ,(const
LPBYTE)path_str.utf16(),len);
    [...]

Is this the best way of determining the actual memory footprint of the
data in a QString?


-- 

Render me gone,                       |||
Bob                                 ^(===)^
---------------------------------oOO--(_)--OOo---------------------------------
                      "If ya can't beat 'em, tariff 'em."
                                   - /Harley-Davidson Motor Company/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090708/0ccab226/attachment.html 


More information about the Qt-interest-old mailing list