Oh, yes it matters a lot! The original version randomly failed (in debug mode builds it always failed).

id.toAscii() converts the 'id' string to ASCII and returns the result in a QByteArray. If you don't store the QByteArray in an object then the QByteArray gets deleted immediately. The fact that you store a C pointer (const char* datastr) to the first QByteArray buffer element does not prevent the deletion and you end up with a dangling pointer to the deleted QByteArray buffer.

There is no problem if we copy the result in a single expression, such as:
std::string s = something.toString().toLatin1();
But this one crashes/produces invalid results:
const char* tmp=something.toString().toLatin1();
std::string s = tmp;