QString, toLatin1(), data(), concatenated
-
I have a QJsonDocument:
QJsonDocument doc(arySetting);
This is converted to Json then to a QByteArray:
QByteArray baJSON = doc.toJson();
At this point baJSON consists of 831 bytes.
Then I strip out the whitespace and convert to a QString:
QString strJSON = strStrip(baJSON);
strJSON is 403 bytes long.
I then convert this back to a byte array:
baJSON = strJSON.toLatin1();
Again, baJSON is 403 bytes long. I then convert this to a const char*:
const char* cpszJSON = baJSON.data();
Now looking in the debugger cpszJSON contains only 100 bytes.
Whats going on ?
-
@SPlatten said in QString, toLatin1(), data(), concatenated:
Whats going on ?
You're simply looking at the output of gdb which does not output all chars of a char* array (since it can get very long) but only the first 100. So you're testing wrong. Use strlen.
-
@SPlatten said in QString, toLatin1(), data(), concatenated:
the application is stuck.
But this for sure does not happen due to the fat the debugger only shows the first 100 bytes of a char* pointer...
-
As I already told you it's the debugger which is showing only the first 100bytes and if you don't trust me use strlen() and/or print the string to e.g. stdout.