[Solved]qml can not recognize the c++ parameters with &
-
Data will be copied anyway, as JavaScript lists and QList are different. It does seem a bit strange, though, especially the part about using only one parameter.
Try usign QVariant, maybe? And then getting the data using QVariant::value<>().
-
wrote on 25 Jun 2013, 06:59 last edited by
[quote author="sierdzio" date="1372142579"]
Try usign QVariant, maybe? And then getting the data using QVariant::value<>().[/quote]QVariant can prevent the copy of the data?
Could you show me an example? -
It might, although it probably won't. I was rather thinking about allowing you to use 2 parameters.
-
wrote on 25 Jun 2013, 07:19 last edited by
Do we have a way to pass heavy data between qml and c++ without copy?
-
By using QObject pointers.
For me, const QString references and QLists of pointers also do work. I don't know the internals of the engine well enough to answer your question with confidence.
-
wrote on 25 Jun 2013, 07:32 last edited by
[quote author="sierdzio" date="1372144978"]By using QObject pointers.
For me, const QString references and QLists of pointers also do work. I don't know the internals of the engine well enough to answer your question with confidence.[/quote]
Could you show me some example?
-
- "link":https://github.com/sierdzio/closecombatfree/blob/master/src/ccfgamemanager.h
- "link":https://github.com/sierdzio/closecombatfree/blob/master/src/logic/ccfenginehelpers.h
- and "link":https://github.com/sierdzio/closecombatfree/blob/master/src/logic/ccfscenariostate.h
Feel free to check out the whole project, it can easily be browsed in Qt Creator.
-
wrote on 25 Jun 2013, 07:38 last edited by
Thanks for your help.
Since a lot of heavy jobs would be done on c++ sites, I hope in the future we could
pass the parameters between c++ and qml by reference. -
wrote on 25 Jun 2013, 08:14 last edited by
Can't find a reasonable way to transform between string and QObject
so I try const&@
/**- @brief find out the different string of new_data compare with the old data
- @param old_data : the old data
- @param new_data : the new data
- @return the combination of the old data and the different string of new_data compare with the old data
- @example old_data = {1, 2, 3, 4}, new_data = {1, 3, 4, 5}, results = {1, 2, 3, 4, 5}
- @caution : qml site could not recognize the parameters with &(even it can, it still copy the parameters rather than take the reference)
-
pass the parameters by const& seems work, but I am not sure it would not copy the data by this way
*/
QList<QString> fileProcess::unique_strs(QList<QString> const &old_data, QList<QString> const &new_data)
{
//awkward solution and maybe meaningless, hope that in the future this could be solved
return set_difference_lazy(const_cast<QList<QString>&>(new_data), const_cast<QList<QString>&>(old_data));
}
@ -
wrote on 25 Jun 2013, 15:37 last edited by
After some experiment, the last post of my solution is useless, the data of
qml and c++ are always copy
11/11