It's known that Qt classes use copy-on-wite when passing by value. So copy isn't done until its needed. I have seen many times passing Qt classes by const reference when only needed read-only access to object. Why do people pass const QString& instead of simple QString if in both cases no copy is done?
This is because magic comes with a price. QString doesn't copy entire string, but it calculates references. Many copyings of QString can slow down the program. If const QString& is sufficient for your needs, why not use it? It is still faster.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With