问题
In JavaScript the highest integer possible is defined via
Number.MAX_SAFE_INTEGER.
and also in C++ can be obtained with the std:
std::numeric_limits<int>::max()
Is there such a constant in QML for ints or doubles?
回答1:
As originally suspected, the 2000000000 number listed in the documentation is incorrect. Also, IMO this is an important value that shouldn't really be subject to such careless approximations. "Around" should only be used when the actual value is unknown for certain or not crucial.
A simple test verifies that the largest possible value for an int property in QML is 2147483647, or as expected 2^31 - 1.
Note that this is different from Number.MAX_SAFE_INTEGER which is a JS thing, and that value is 2^53 - 1 - substantially higher than what int will give you. Number is a 64 bit real data type, and it supports integers by using the 53 fraction bits of the number, the 11 exponent bits are left unused.
回答2:
Another alternative is to use IntValidator. By default, top and bottom property contains the maximum and minimum Qt int value.
readonly property IntValdiator intValdiator: IntValidator {}
readonly property int MAX_VALUE: intValidator.top
readonly property int MIN_VALUE: intValidator.bottom
回答3:
The constants you need are -Infinity and Infinity, or Number.NEGATIVE_INFINITYand Number.POSITIVE_INFINITY
来源:https://stackoverflow.com/questions/41378583/qml-highest-number-float-integer-possible