Compare to qml string "10" and "9"

Compare to qml string "10" and "9"

qml comparison operators
qml string length
qml string contains
qml string functions
qml concatenate string
qml string to int
qml string split
string qml

I've tried to compare qml string "10" biggest than "9", but console.log sent me false

console.log("10" > "9");

console output false

qml: false

Explain to me why this doesn't work


Explain to me why this doesn't work

This is really a JavaScript question because that is the language used by QML processor. You're comparing strings, not numbers. Here's a good explanation of string (and in general) comparison in JavaScript.

I will quote the relevant part and present my own example:

To see whether a string is greater than another, JavaScript uses the so-called "dictionary" or "lexicographical" order. In other words, strings are compared letter-by-letter.

The algorithm to compare two strings is simple:

  1. Compare the first character of both strings.
  2. If the first character from the first string is greater (or less) than the other string’s, then the first string is greater (or less) than the second. We’re done.
  3. Otherwise, if both strings’ first characters are the same, compare the second characters the same way.
  4. Repeat until the end of either string.
  5. If both strings end at the same length, then they are equal. Otherwise, the longer string is greater.

console.log("10" > "9");    // false, first character is smaller
console.log("9" > "8");     // true, first character is larger
console.log("9" > "08");    // true, first char. is larger
console.log("10" > "09");   // true, first char. is larger
console.log("100" > "11");  // false, second char. is smaller

string QML Basic Type, Strings have a length attribute that holds the number of characters in the string. QML extends the JavaScript String type with a arg() function to support value� Lexically compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other string. Equivalent to compare(*this, other). int QString:: compare (const QString & other, Qt::CaseSensitivity cs) const. This function overloads compare(). Same as compare(*this, other, cs). This function was introduced in Qt 4.2. int QString:: compare (const QLatin1String & other, Qt::CaseSensitivity cs = Qt


If you know the strings will be integers always (assuming they will come from some variable) you can change your code to parse them and the comparison will work correctly:

console.log(parseInt("10") > parseInt("9"));

QML If statement matching strings in a variable ?, I am searching a way to match words within a string message I received from websockets which is stored in a variable using an IF statement. so� Compares this string with the other string and returns an integer less than, equal to, or greater than zero if this string is less than, equal to, or greater than the other string. The comparison is performed in a locale- and also platform-dependent manner. Use this function to present sorted lists of strings to the user.


You can use this workaround:

console.log("10"*1 > "9"*1); // true

If you are going to use parseInt take care about the radix parameter. In previus example there is no radix parameter, so the interpreter will fall back to the default behaviour, which typically treats numbers as decimal, unless they start with a zero (octal) or 0x (hexadecimal)

What the Heck is the Strict Comparison Operator, Hi Brad I'm new to Qt Quick and while I've been learning the QML That is if you try to compare a string to an Number that is exactly what will� C# String.Compare method compares two strings in C#. You can also use C# String.Equals method and StringComparer class and its method. This article and code examples demonstrate how to compare strings in C# using these different methods.


[Qt-qml] qml locale aware string comparison, Hi guys,. Are there are any plans to implement locale aware string comparison api for QML? What about any other locale aware properties, including but not� The algorithm to compare two strings is simple: Compare the first character of both strings. If the first character from the first string is greater (or less) than the other string’s, then the first string is greater (or less) than the Otherwise, if both strings’ first characters are the same,


TestCase QML Type, This function dynamically creates a QML object from the given qml string with the specified compare(findChild(item, "childObject"), expectedChildObject);. The comparison operators which use three characters vs. two are called the Strict Comparison Operator and is not new to QML but rather part of the ECMAScript standard. For those unfamiliar ECMAScript is the actual scripting language standardized in ECMA-262 and ISO/IEC 16262 .


[Qt-qml] qml locale aware string comparison, [Qt-qml] qml locale aware string comparison. Alan Alpert alan.alpert at nokia.com. Fri Dec 23 02:18:04 CET 2011. Previous message: [Qt-qml] qml locale aware� In qml the qsTr() does take arguments in the same way as QString does. You can write qsTr("%1 copied").arg(filename). This will translate the string and then format it using the argument. At least it works fine with string arguments.