Right way to pass QString to methods

From Qt Wiki
Jump to navigation Jump to search

Template:ArticleMetaData

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.