In my program I have a tree-like architecture of objects that I need to access from the QML. I cannot figure out how can I create a Q_PROPERTY
getter function, that would allow me to access the item at the Index of my choosing. The function looks like this in the C++ part:
/**
* @brief Risk object getter function.
* @param index: The index of the risk from the \ref m_risks container.
* @return Pointer to the risk object if \p index is valid. Otherwise 0.
*/
CRiskData* CVessel::getRisk(const int index)
{
if (index >= m_risks.length())
return nullptr;
return m_risks[index];
}
But it seems that this QML <-> Qt property communication system only allows a getter that has no input parameters. I tried to define it like this:
Q_PROPERTY(CRiskData* risk READ getRisk)
I get a compiler error that no matching function is found for:
moc_cvessel.cpp:122: error: no matching function for call to 'CVessel::getRisk()'
case 0: *reinterpret_cast< CRiskData**>(_v) = _t->getRisk(); break;
^
So MOC created the function with no input arguments... Is there any way around this? The goal is to be able to access each element of an object from the QML side in a hierarchical way.
Q_INVOKABLE
to make it a function that can have arguments, however, this might not be handy with regards to binding, but that cannot be examined since that part of code is not given – Amfasis