Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-76025 Specify the QML language and write a QML-to-C++ compiler
  3. QTBUG-112875

qmlsc: Support more standard and Qt-defined fixed-width numeric types

    XMLWordPrintable

Details

    Description

      In particular, we don't have any support for 8-bit and 16-bit numbers.

       

      Code
      cppobj.h

      #ifndef CPPOBJ_H
      #define CPPOBJ_H
      
      #include <QQmlEngine>
      
      class CppObj : public QObject
      {
          Q_OBJECT
          QML_ELEMENT
          QML_SINGLETON
      
      public:
          CppObj(QObject* parent = nullptr) : QObject(parent) {}
      
      public:
          Q_INVOKABLE qint8 qint8Foo() const { return 42; }
          Q_INVOKABLE int8_t int8_tFoo() const { return 42; }
          Q_INVOKABLE quint8 quint8Foo() const { return 42; }
          Q_INVOKABLE uint8_t uint8_tFoo() const { return 42; }
          Q_INVOKABLE qint16 qint16Foo() const { return 42; }
          Q_INVOKABLE int16_t int16_tFoo() const { return 42; }
          Q_INVOKABLE quint16 quint16Foo() const { return 42; }
          Q_INVOKABLE uint16_t uint16_tFoo() const { return 42; }
          Q_INVOKABLE qint32 qint32Foo() const { return 42; }
          Q_INVOKABLE int32_t int32_tFoo() const { return 42; }
          Q_INVOKABLE quint32 quint32Foo() const { return 42; }
          Q_INVOKABLE uint32_t uint32_tFoo() const { return 42; }
          Q_INVOKABLE qint64 qint64Foo() const { return 42; }
          Q_INVOKABLE int64_t int64_tFoo() const { return 42; }
          Q_INVOKABLE quint64 quint64Foo() const { return 42; }
          Q_INVOKABLE uint64_t uint64_tFoo() const { return 42; }
          Q_INVOKABLE qlonglong qlonglongFoo() const { return 42; }
          Q_INVOKABLE qulonglong qulonglongFoo() const { return 42; }
          Q_INVOKABLE qreal qrealFoo() const { return 42; }
          Q_INVOKABLE qfloat16 qfloat16Foo() const { return 42; }
          Q_INVOKABLE float floatFoo() const { return 42; }
          Q_INVOKABLE double doubleFoo() const { return 42; }
      };
      
      #endif // CPPOBJ_H
      

      main.qml

      import QtQuick
      import QmlscNumbers
      
      Window {
          width: 640
          height: 480
          visible: true
      
          // Not OK
          function qint8Bar() { console.log(CppObj.qint8Foo()) }
          function int8_tBar() { console.log(CppObj.int8_tFoo()) }
          function quint8Bar() { console.log(CppObj.quint8Foo()) }
          function uint8_tBar() { console.log(CppObj.uint8_tFoo()) }
          function qint16Bar() { console.log(CppObj.qint16Foo()) }
          function int16_tBar() { console.log(CppObj.int16_tFoo()) }
          function quint16Bar() { console.log(CppObj.quint16Foo()) }
          function uint16_tBar() { console.log(CppObj.uint16_tFoo()) }
          function int32_tBar() { console.log(CppObj.int32_tFoo()) }
          function uint32_tBar() { console.log(CppObj.uint32_tFoo()) }
          function int64_tBar() { console.log(CppObj.int64_tFoo()) }
          function uint64_tBar() { console.log(CppObj.uint64_tFoo()) }
          function qfloat16Bar() { console.log(CppObj.qfloat16Foo()) }
      
          // OK
          function qint32Bar() { console.log(CppObj.qint32Foo()) }
          function quint32Bar() { console.log(CppObj.quint32Foo()) }
          function quint64Bar() { console.log(CppObj.quint64Foo()) }
          function qint64Bar() { console.log(CppObj.qint64Foo()) }
          function qlonglongBar() { console.log(CppObj.qlonglongFoo()) }
          function qulonglongBar() { console.log(CppObj.qulonglongFoo()) }
          function qrealBar() { console.log(CppObj.qrealFoo()) }
          function floatBar() { console.log(CppObj.floatFoo()) }
          function doubleBar() { console.log(CppObj.doubleFoo()) }
      }
      
      

       

      Compiler output

      warning: Main.qml:10:43: Could not compile function qint8Bar: return type qint8 cannot be resolved [compiler]
      warning: Main.qml:11:44: Could not compile function int8_tBar: return type int8_t cannot be resolved [compiler]
      warning: Main.qml:12:44: Could not compile function quint8Bar: return type quint8 cannot be resolved [compiler]
      warning: Main.qml:13:45: Could not compile function uint8_tBar: return type uint8_t cannot be resolved [compiler]
      warning: Main.qml:14:44: Could not compile function qint16Bar: return type qint16 cannot be resolved [compiler]
      warning: Main.qml:15:45: Could not compile function int16_tBar: return type int16_t cannot be resolved [compiler]
      warning: Main.qml:16:45: Could not compile function quint16Bar: return type quint16 cannot be resolved [compiler]
      warning: Main.qml:17:46: Could not compile function uint16_tBar: return type uint16_t cannot be resolved [compiler]
      warning: Main.qml:18:45: Could not compile function int32_tBar: return type int32_t cannot be resolved [compiler]
      warning: Main.qml:19:46: Could not compile function uint32_tBar: return type uint32_t cannot be resolved [compiler]
      warning: Main.qml:20:45: Could not compile function int64_tBar: return type int64_t cannot be resolved [compiler]
      warning: Main.qml:21:46: Could not compile function uint64_tBar: return type uint64_t cannot be resolved [compiler]
      warning: Main.qml:22:46: Could not compile function qfloat16Bar: return type qfloat16 cannot be resolved [compiler]
      

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes