Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-84738

unable to define custom basic numeric type(like real) for qml

    XMLWordPrintable

Details

    • All

    Description

      this is somewhat a bug and a feature-request, financial applications needs more precise numeric types that are not available by default in qml, c/c++ - im talking about Decimal.

      there are a lot of custom c/c++ Decimal libraries on the market developed by intel, ibm etc.

      on the c++ side its not a problem, the problem starts when developing qml gui.

      printing such values is okay - can be acheived  via:

      class Decimal {
      };
      Q_DECLARE_METATYPE(Decimal)
      QMetaType::registerConverter(&Decimal::ToQString);

      but thats all - the problem are operators

      there is no (public-api) way to make qml know about such type operators so math is complicated in qml.

      would be nice if one could make something like this working:

      property Decimal foo: 1.22
      property Decimal bar: 1.55
      property Decimal added: foo + bar//(and other math operators)

      for now our workaround is that we created sub class ex:  qmlDecimalMath that derives from QObject that has alot of Q_INVOKABLE functions that do math in c++ and returns values

      for example:

      Q_INVOKABLE Decimal add(Decimal _first, Decimal _second){ return _first + _second; }
      

      but doing sometimes complex math is quite painful this way and very very hard to read(code)

       

      what we are looking for is ability to create our own basic type like real (in qml)

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              meomic Michal M
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes