str.toAscii().data() is the same as str.toLatin1().data unless you use setCodecForCStrings().
Note that there is a temporary object being created here, so the return value isn't valid when the statement is complete. So:
ucTest = (unsigned char *) str.toLatin1().data();
ucTest = (unsigned char *) str.toLatin1().data();
To copy to clipboard, switch view to plain text mode
Will never work correctly, but this will:
myFunc((unsigned char *) str.toLatin1().data());
myFunc((unsigned char *) str.toLatin1().data());
To copy to clipboard, switch view to plain text mode
myFunc will be passed a pointer which will not be deleted until after myFunc returns.
If you want to pointer to remain valid, create a QByteArray:
ucTest = (unsigned char *) ascii.data();
QByteArray ascii = str.toLatin1();
ucTest = (unsigned char *) ascii.data();
To copy to clipboard, switch view to plain text mode
Bookmarks