Solved Component problems
-
I have a function defined in main.qml:
function showNumericKeyboard(objectName, modelButtons, primaryIndex, settingValue, hintMsg, accepted) { var comp = Qt.createComponent("qrc:/WizardPopupNumericKeyboard.qml"); comp.createObject(application, { "objectName": objectName , "modelButtons": modelButtons , "primaryIndex": primaryIndex , "settingValue": settingValue , "hintMsg": hintMsg , "accepted": accepted }) }
I call the function like this:
MouseArea { anchors.fill: parent onClicked: { showNumericKeyboard("systemDialog", [qsTr("Cancel"), qsTr("Finished")], 1, modelData, qsTr(""), theBool); } }
in
PopupNumericKeyboard.qml
I try to edit the value of accepted and I get an error:Error: Invalid write to global property "accepted"
what am I doing wrong?
-
Try renaming your
accepted
parameter, it apparently clashes with some global property you have made (or maybe it's built-in but I doubt it). -
@sierdzio Interesting, now it's giving me an entirely different error after changing the name:
ReferenceError: theValue is not defined
it seems odd because I am printing out
hintMsg
which I set the text to be "Hint Message" just before and it prints just fine:Component.onCompleted { console.info(hintMsg) console.info(theValue) }
output:
qml: Hint Message qrc:/WizardPopupNumericKeyboard.qml:21: ReferenceError: theValue is not defined
-
I am not sure what this means, I am very confused. I swapped some things around:
function showNumericKeyboard(objectName, modelButtons, primaryIndex, settingValue, theValue, hintMsg) { var comp = Qt.createComponent("qrc:/WizardPopupNumericKeyboard.qml"); comp.createObject(application, { "objectName": objectName , "modelButtons": modelButtons , "primaryIndex": primaryIndex , "settingValue": settingValue , "theValue": theValue , "hintMsg": hintMsg }) }
showNumericKeyboard("systemDialog", [qsTr("Cancel"), qsTr("Finished")], 1, modelData, qsTr("Hint Message"), itIsABool);
Component.onCompleted: { console.info(hintMsg) console.info(theValue) }
output:
qml: false qrc:/WizardPopupNumericKeyboard.qml:21: ReferenceError: theValue is not defined
-
Apparently I had to define the bool value within
WizardPopupNumericKeyboard.qml
? Not sure why but as soon as I instantiated it there as a property:property bool theBool: bool
then it worked:
Component.onCompleted: { console.info(hintMsg) console.info(theBool) }
output:
qml: Hint Message
qml: false