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

QString::arg() convert floating type to integer

    XMLWordPrintable

Details

    Description

      QString::arg() converts float wrapper type using type conversion operator to integer, the same goes for double. This issue is not present in Qt 6.8

      #include <QCoreApplication>
      #include <QDebug>
      
      class MyFloat {
          float value;
      public:
          MyFloat(float f0) : value(f0) {}
          // Type conversion operator
          operator float() {
              return value;
          }
      };
      
      int main(int argc, char** argv)
      {
          QCoreApplication app(argc, argv);
          
          MyFloat mf = 5.1;
          auto var = QString("%1").arg(mf);    
          qInfo() << ((var == "5.1") ? "Equal, var value is: " : "Not Equal, var value is: ") << var;
          return 0;
      }
       

      Attachments

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

        Activity

          People

            mmutz Marc Mutz
            kitruong Kinh Truong
            Votes:
            7 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes