Hbi Giu Hbi Giu - 1 year ago 91
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;

Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download