I have a QString that I would like to convert into a char* not a QChar* because I’ll be passing it into a method that takes a char*, however I can’t convert it without it getting a const char*. For example I have tried:
QString name = "name";
QByteArray byteArray = name.toUtf8();
myMailboxName = byteArray.constData();
and
QString name = "name";
QByteArray byteArray = name.toUtf8();
myMailboxName = byteArray.data();
where myMailboxName is a private char* in my class. However I get an error because it is returning a const char* and can’t assign it to a char*. How can I fix this?
This is because data() returns the address of the buffer in the bytearray, you can read it, but obviously you should not write it.
You have your own buffer outside the bytearray. If you want the data, you should copy the buffer of bytearray into the myMailBoName.
use memcpy function