Problem with modelData. QVarient questions.
-
I want to start off by apologizing if this questions seems vague. It is that way because I am confused and don't know what's going on.
My question is regarding a variable I am working with called
modelData. In this application (I did not build) there is a portion of code which confuses me:Component.onCompleted: { ... else if(typeof(modelData.value) === "string" && modelData.optionsList.length === 0) { modelData.settingInvalid ? value_container.allowNext = false : value_container.allowNext = true ldr.sourceComponent = textEntryComponent value_container.objectName = "textbox" } else if(typeof(modelData.value) === "number" && modelData.optionsList.length !== 0) { ldr.sourceComponent = listOptionComponent value_container.objectName = "list" } ....How is it possible for this
modelData'svalueto be either a string or a number? Does that mean I am dealing with two different variables both calledmodelDataor is it possible that this variable is changing it's initialization on the back-end somehow? -
I want to start off by apologizing if this questions seems vague. It is that way because I am confused and don't know what's going on.
My question is regarding a variable I am working with called
modelData. In this application (I did not build) there is a portion of code which confuses me:Component.onCompleted: { ... else if(typeof(modelData.value) === "string" && modelData.optionsList.length === 0) { modelData.settingInvalid ? value_container.allowNext = false : value_container.allowNext = true ldr.sourceComponent = textEntryComponent value_container.objectName = "textbox" } else if(typeof(modelData.value) === "number" && modelData.optionsList.length !== 0) { ldr.sourceComponent = listOptionComponent value_container.objectName = "list" } ....How is it possible for this
modelData'svalueto be either a string or a number? Does that mean I am dealing with two different variables both calledmodelDataor is it possible that this variable is changing it's initialization on the back-end somehow?@Circuits said in Problem with modelData. QVarient questions.:
How is it possible for this modelData's value to be either a string or a number?
Why shouldn't it be? Also, this code looks like it's supplying generic code:
modelDatais some data value from the model, it might come from any row and column, so the code says if it's a string do this and if it's a number do that.Code is JavaScript, which is an untyped language. Unlike, say, C++,
modelDatacan hold any value type, it never gets pre-declared asstrorintor anything. If anything, think of it as aQVariant, kind of. -
@Circuits said in Problem with modelData. QVarient questions.:
How is it possible for this modelData's value to be either a string or a number?
Why shouldn't it be? Also, this code looks like it's supplying generic code:
modelDatais some data value from the model, it might come from any row and column, so the code says if it's a string do this and if it's a number do that.Code is JavaScript, which is an untyped language. Unlike, say, C++,
modelDatacan hold any value type, it never gets pre-declared asstrorintor anything. If anything, think of it as aQVariant, kind of. -
@JonB OH ic, so your saying the type is probably being determined on the front end? In other words, somewhere (prior to this code) it's
valueis being specified to be either anintor astringor what-have-you. Is that what your saying?@Circuits
I suppose the short answer is yes, though its rather determined in the backend of code, which means not in the UI.The data presumably started life as some value in some row/column of something. That type may have been preserved, or it may have got converted all over the place, who knows.
Actually the code tests
modelData.value. JavaScripttypeof()returns the type that is currently stored inmodelData.value. At some point something setmodelData.value = "a string"ormodelData.value = 99ormodelData.value = -123.45or whatever. It looks like the code then decides what kind component/widget would be suitable for displaying that type of value.