You clearly have an invalid code. It's the same like if you wrote:
char *cstr = str.toAscii().data();
printf("%s\n", cstr);
QString str("xxxxx");
char *cstr = str.toAscii().data();
printf("%s\n", cstr);
To copy to clipboard, switch view to plain text mode
Second line of the above code is invalid because data() returns a pointer to internal data of the byte array that gets destroyed immediately as it is a temporary object. From what I understand you are doing exactly the same in your code and Qt has nothing to do with it.
Bookmarks