Hello all,
I'm using some C functions that expect old fashionned ascii string paths, but I'm using Qt utilities to handle the paths.
Here is a sample static method I wrote:
char *PathUtil
::toWinAscii(QString fullpath
) {
char *s = ba.data();
#if WIN32
char *p = s;
while(*p){if(*p == '/')*p = '\\'; p++;}// convert Qt's separators to Windows compatible separators
#endif
return s;
}
char *PathUtil::toWinAscii(QString fullpath)
{
QByteArray ba = fullpath.toLocal8Bit();
char *s = ba.data();
#if WIN32
char *p = s;
while(*p){if(*p == '/')*p = '\\'; p++;}// convert Qt's separators to Windows compatible separators
#endif
return s;
}
To copy to clipboard, switch view to plain text mode
Now if I do thousands of calls of this function (because I'm dealing with thousands of files), I expect to get a lot of memory eaten up.
Should I free the memory allocated by data() with free or delete []?
My guess is that I should get into the sources, but I still wonder whether this is discussed in the documentation.
UPDATE:
Sorry, but I am not sure if it really works at all. Is the value being returned treated as an "automatic variable", and disappear on return from the method?
Bookmarks