Hbi Giu Hbi Giu - 10 months ago 60
C++ Question

Qml and C++ interaction: return by pointer or by copy

So I have a Q_PROPERTY exposed to qml like below

Q_PROPERTY(QVariantMap info READ getInfo NOTIFY infoChanged)

QVariantMap ProfileInfo::getInfo()
return info;

Now, my question is would the approach below would be more efficient and less costly?

Q_PROPERTY(QVariantMap* info READ getInfo NOTIFY infoChanged)

QVariantMap* ProfileInfo::getInfo()
return &info;


Just slightly more efficient (QVariantMap uses implicit sharing, so a copy is not expensive), but your biggest problem is that QML doesn't know how to deal with a QVariantMap *, only with a QVariantMap (see here).