Hi -
I wrote:
> (const char*) object.toAscii()
> This is wrong on several levels. In Qt4 and probably earlier,
> toAscii() returns a (temporary) QByteArray object, not a C string.
> Any casting to hide this leads to direct junk, e.g., failure to save
> pmchart view state to requested file names, or with actual readable
> metric names. [...]
Looking over the evolving Qt API, I think I overestimated this effect,
due to the code's reliance on the
QByteArray::operator const char * () const
member function. So maybe (const char*) qstring.toAscii() is not
wrong after all, merely scary due to the cast.
> [...] This too is imperfect, as the QByteArray object is
> temporary, and will be deallocated at the next statement (;) boundary,
> which makes the const char*'s contain junk again. So, cases where
> such pointers are stored beyond a statement need to be strdup()'d.
Whereas this complication is definitely still there.
I'll test out a less invasive patch for just the second case.
- FChE
|