Can Q_INVOKABLE function return reference ?
-
Can Q_INVOKABLE function return reference ?
For example: Q_INVOKABLE const QString& myFunc(int _myInt);
-
I don't see any mention in the docs it can't. Check whether it works then you'll know it for sure.
-
I notice you post it in QtQuick subforum. Remember that Q_INVOKABLE is just a first step in passing a value to QML. Even if that works, conversion in QML engine might not. Also good to bare in mind is the fact that QString is implicitly shared, so maybe a standard QString return would do without performance penalty.
Best course of action is - as warjan suggested - to try it out. Please post your results here if you don't mind :)
-
I second sierdzio's request for you, aabc to post about your findings.
Offtopic: Damn, I'm so used to giving feedback in form of +1 or Like that I miss those here.
-
I will test it
-
After some more reading I can bet that you can use Q_INVOKEABLE with function returning references and you can't do it for QML and C++ data exchange, because data is transferred between those in QVariant and it can't hold references if I understand it correctly.
http://doc.qt.digia.com/qt/qtbinding.html#exchanging-data-between-qml-and-c
http://doc.qt.digia.com/qt/qvariant.html#Type-enum -
"you can’t do it for QML and C++ data exchange"
For what other reason should I use Q_INVOKEABLE ?
-
AFAIK it's used for slot and signals mechanism and then some http://qt-project.org/doc/qt-4.8/qmetaobject.html#details you can call invokeMethod on Q_INVOKEABLE functions.
-
[quote author="aabc" date="1358336600"]"you can’t do it for QML and C++ data exchange"
For what other reason should I use Q_INVOKEABLE ?[/quote]There are all sorts of uses outside QML. This macro is much older than QML and is part of the Meta-Object system.