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

Doubles are implicitly converted to integers when passed as a QVariant from QML into C++

    XMLWordPrintable

Details

    Description

      When invoking a C++ method from Qt with a QVariant parameter which was defined in QML as a double, if that double lies on a whole number boundary, it is passed as a QVariant(int) rather than a QVariant(double)

      property double test1 = 1.0
      property double test2 = 1.1
      function testDouble() {
         CCode.test_value(test1);
         CCode.test_value(test2);
      }
      
      class CCode : public QObject {
      Q_OBJECT
      public:
         Q_INVOKABLE void test_value(const QVariant& value) {
            qDebug() << value;
         }
      }
      

      Output:
      QVariant(int, 1)
      QVariant(double, 1.1)

      Attachments

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

        Activity

          People

            shausman Simon Hausmann
            dednick Nick Dedekind
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes