I am using a 3rd party library with Qt that requires char*
strings. I am using the following code to convert my QString to a char*
char* toCharArray(const QString &string)
{
QByteArray bytes = string.toLocal8Bit();
char* data = new char[bytes.count() + 1];
strcpy(data, bytes.data());
return data;
}
// later on...
3rdPartyObject->3rdPartyMethod(toCharArray("someFile"));
What can I do to make sure the char*
I return is cleaned up, apart from doing something messy like this?
char* path = toCharArray("someFile");
3rdPartyObject->3rdPartyMethod(path); // The class and method called can differ
delete[] path;