Namespaces
Variants
Actions

Right way to pass QString to methods

Jump to: navigation, search
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.

This page was last modified on 11 October 2012, at 04:18.
110 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved