On Mon, Jul 29, 2002 at 10:02:23AM -0400, Kuba Ober wrote:
> It does return a null terminated char const *, although please notice that 
> this pointer may point to garbage on any subsequent line of your code, if the 
> source QString was destroyed.
> 
> Thus, I'd always do this (unless I'm the one owning the QString):
> 
> char mybuf[512];
> strncpy(mybuf, selectedFile().latin1(), sizeof(mybuf) - 1);
> mybuf[sizeof(mybuf) - 1] = 0;
> // sizeof()-1 so that the mybuf will always be zero-terminated
> // even if latin1() returns a 512- or longer string

And why don't you use

 std::string mystr = selectedFile().latin1();

?

Looks simpler and does not have this strnage 512-char restriction?

Andre'

-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)

Reply via email to