The scope of temporary objects is the end of the statement (i.e. the semi-colon). The temporary QByteArray is valid until the end of the some_c_api() function call.
Something like this would be risky:
const char *s = theString.toLatin1().constData();
// the byte array disappears here but you are holding a pointer to some of its deallocated memory
some_c_api(s);
// potential boom
const char *s = theString.toLatin1().constData();
// the byte array disappears here but you are holding a pointer to some of its deallocated memory
some_c_api(s);
// potential boom
To copy to clipboard, switch view to plain text mode
Bookmarks