How to get QML (5.15) to understand that when I declare a property to be an integer, I WANT it to be treated as an INTEGER, and NOT a FUNCTION!
-
QML 5.15
I have a control. It allows a value to be incremented or decremented by a specified amount.
The display can only hold up to 3 digits, so it must be less than 1000.The user can specify an adjustment value, adjustmentDelta, which defaults to 50.
For those that need code to understand how that translates,
property int adjustmentDelta: 50
The minimum value is zero, the maximum is set to, (1000 - adjustmentDelta). Again, for those that require rudimentary code,
property int theMinValue: 0 property int theMaxValue: (1000 - adjustmentDelta)
(And, honestly, give us a way to define LOCAL properties that are NOT visible outside the class WITHOUT creating a QtObject! Far too many hacks in QML to do basics.)
When I attempt to test values to then show a message block that indicates if the minimum or maximum has been reached, it fails a simple boolean check, if (thValue >= theMaxValue), because it is treating, theMaxValue, as a function.
The values have not changed within the module once theMaxValue was set. adjustmentDelta is still the same and 1000 is still the same. Even a function of such simplicity should return the same value consistently.
Yes, I could write a ridiculously simple and wasteful function to return (1000 - adjustmentDelta) and assign theMaxValue to that return value, but again, just another way of hacking around QML.
Once more, theMaxValue is a property defined as an integer. Let me use it as an INTEGER!
-
Really didn't get your problem. The code below works fine:
property int adjust: 50 property int min: 0 property int max: (1000 - adjust) property int current: 99942 Button { anchors.centerIn: parent text: "Test" onClicked: { console.log(adjust, min, max, current, current >= max) console.log(typeof max) } }
Output:
qml: 50 0 950 99942 true qml: number
-
Result from the following:
print("\nHighPressureLimit: increase - (theValue => theMaxValue)="+(theValue => theMaxValue).toString()+", (theValue <= theMinValue)="+(theValue <= theMinValue).toString()+"\n")
is,
HighPressureLimit: increase - (theValue => theMaxValue)=function() { [native code] }, (theValue <= theMinValue)=false
It's a BOOLEAN expression! Even if it contains a function, it should still result in true or false. (As the test of the min value obviously does.)
-
This is not an property feature, nor a QML feature. The same effects you can achieve with code below:
let variable; console.log((variable => 42))
This is how V4 engine and JavaScript works. But I think you just messed with syntax, cuz
=>
isn't an comparison, it is new arrow function syntax. Just use>=
instead, and there is no need to convert to string. E.g.:console.log("3 >= 5: " + (3 >= 5))
-
The following...
print("HighPressureLimit: increase - typeof theMaxValue = "+typeof theMaxValue+"\n")
print("HighPressureLimit: increase - typeof theMinValue = "+typeof theMinValue+"\n")
print("HighPressureLimit: increase - typeof theValue = "+typeof theValue+"\n")
print("HighPressureLimit: increase - typeof (theValue => theMaxValue) = "+typeof (theValue => theMaxValue)+"\n")
print("HighPressureLimit: increase - typeof (theValue <= theMinValue) = "+typeof (theValue <= theMinValue)+"\n")Results in...
qml: HighPressureLimit: increase - typeof theMaxValue = number
qml: HighPressureLimit: increase - typeof theMinValue = number
qml: HighPressureLimit: increase - typeof theValue = number
qml: HighPressureLimit: increase - typeof (theValue => theMaxValue) = function <- NOTE: This is NOT what I want.
qml: HighPressureLimit: increase - typeof (theValue <= theMinValue) = boolean -
=> isn't valid c++ either.