Between avoid making a mistake (which means understand what implicit sharing is) to "one should never do that." there is a big difference.its not about const. It about temporary object. Qt docs has mentioned to avoid this mistake.(Read the QByteArray docs)
If YOU read the docs for QByteArray::data() you will see, that they don't say anything about NOT using it.
They do say however:
So you definitively CAN and SHOULD use that for cases where it is needed - provided you READ the documentation, and aware of the pitfalls.The pointer remains valid as long as the byte array isn't reallocated or destroyed. For read-only access, constData() is faster because it never causes a deep copy to occur.
This function is mostly useful to pass a byte array to a function that accepts a const char *.
There are ofte several possibles to do the same thing - and one should look at the best suited option.
People, you should really stop with these "NEVER DO <something> OR THE WORLD WILL END" assertions.
The methods are there to be used, just make sure you understand what you are doing when you use them and what the consequences are.
So relax.
Bookmarks