Right way to pass QString to methods
Article Metadata
Compatibility
Platform(s): all
Article
Keywords: Qt, QString
Created: gnuton
(20 Jun 2010)
Last edited: hamishwillee
(11 Oct 2012)
A common programming mistake is passing QString as value to methods.
void method(const QString str);
This is allowed but it is not so efficient even if QString is implicitly shared .
A more efficient way is passing the const reference instead of the value.
void method(const QString& str);
This is valid also for other objects.


(no comments yet)