QML How to maintain property reference?
-
I have a property:
dataLink: api.testData.testLink
I want the above to be maintained like a pointer / reference, but instead at runtime I can see instead dataLink contains the actual value. In the QML file dataLink is defined as:
property var dataLink
api is an alias to the QML object:
readonly property alias api : datahlpr
Is there a way or type that will keep the reference intact so when its called I can get a fresh value ?
[Edit 1] The problem I'm having is that whilst initially dataLink is assigned api.testData.testLink when the application runs, my code resolves api.testData.testLink to a numeric value which is correct, however I don't want the numeric value assigned to dataLink, I will take another look as it sounds like a simple error...
[Edit 2] api.testData.testLink is a demonstration link to an entry in a QQmlPropertyMap. I'm using Qt Creator to debug and I can see that what is assigned to dataLink is not the original reference but what it points to, e.g. -21352 , if I then assign dataLink to something else I don't get the original link I get the value -21352. After a little research I found that I can use Object.assign(dataLink) to create a copy of the link, but I don't think this works correctly as I cannot get the same results. Can anyone help me please?
[Edit 3] Another observation in Qt Creator in the QML Debugger Console:
qrc:/DataModel.qml:45: Error: Cannot assign QJSValue to void* qrc:/DataModel.qml: 45
in an effect to find a solution I changed the type of the property to void*.
[Edit 4] dataLink is defined in the QML as:
property var dataLink
If I assign something to it, the original api.testData.testLink, dataLink shows in Qt Creator as having the value that api.testData.testLink points to. What I need is to maintain the reference, so it the location that the reference points to changes so does the value assigned to dataLink, however it seems that dataLink is not being created as a reference because the translation from C++ of api.testData.testLink is not a reference but is the value of what it references....can anyone help?
[Edit 5] A bit more information on the definition of api.testData.testLink:
api is a property in the QML document:readonly property alias api : datahlpr
datahlp is the ID of the QML document reference:
DataMngr { id: datahlpr onDataUpdate: { logMessage("UDT: " + rLabel.text + ", Data: " + dblData) } onInterface: { logMessage("UDT: " + rLabel.text + ", Interface Status: " + blnState_) } onToolTip: { if ( root.blnValid !== true ) { return } var blnVisible = (typeof strToolTip_ === "string" && strToolTip_.length > 0) if ( blnVisible === true ) { var strTagName = root.label rText.color = root.argbStale rImage.ToolTip.text = strToolTip_ if ( api.valid(root.label) !== true ) { rImage.source = cstrInvalid } else if (api.interfaceStatus(strTagName) === true) { rImage.source = cstrStale } else { rImage.source = cstrLinkFail } } else { rText.color = root.argbData } rImage.ToolTip.visible = blnVisible && ma.containsMouse rImage.visible = blnVisible } } `` **testData** is a property defined in the **C++** class:
Q_PROPERTY(QQmlPropertyMap* testData READ pTestData CONSTANT)
And **testLink** is a location in the property map:
static const QString scstrTestLink("testLink");
...
m_testData->insert(scstrTestLink, dblTestLink());**m_testData** is a member of the **C++** class defined as:
std::unique_ptr<QQmlPropertyMap> m_testData;