[Interest] Advanced QString::arg overloads from QML?

Elvis Stansvik elvstone at gmail.com
Mon May 30 18:08:41 CEST 2016


Den 30 maj 2016 4:49 em skrev "Jérôme Godbout" <jerome at bodycad.com>:
>
> You may want to convert the number from javascript before setting the arg:
>
> Int:
> myIntValue.toString(10)
> Float:
> myFloatValue.toFixed(2)
> myFloatValue.toPrecision(6)
>
> For leading 0 on 16 value:
> ("000000000000000" + myIntValue.toString(10)).substr(-16)

Alright. Would have been neat if more of the .arg overloads were available.
But at the moment I have a utility JS function to do it, similar to the
above.

Thanks,
Elvis

>
> Jerome
>
> On Sun, May 29, 2016 at 6:36 AM, Elvis Stansvik <elvstone at gmail.com>
wrote:
>>
>> Hi all,
>>
>> Is there any way to tap into the functionality of the various
>> QString::arg overloads such as
>>
>>     http://doc.qt.io/qt-5/qstring.html#arg-4
>>
>> from QML?
>>
>> I know QML extends the string type with .arg, but it seems it only
>> supports one argument.
>>
>> I'd like to do
>>
>>     '%1'.arg(value, 2, 10, '0')
>>
>> to zero-pad to 2 digits.
>>
>> Thanks,
>> Elvis
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160530/9c9cbeb3/attachment.html>


More information about the Interest mailing list