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

QString::arg() convert floating type to integer

XMLWordPrintable

    • 84263b5cf (dev), d43337e7f (dev), d9d7eeeb4 (6.10), 6716998a3 (6.10), b03703bbb (6.9), 4a791c9d0 (6.9), b6313b2b0 (tqtc/lts-6.8), 066d496c4 (tqtc/lts-6.5)
    • Foundation Sprint 134, Foundation Sprint 135, Foundation Sprint 136, Foundation Sprint 137, Foundation Sprint 138

      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;
      }
       

        For Gerrit Dashboard: QTBUG-138471
        # Subject Branch Project Status CR V

            mmutz Marc Mutz
            kitruong Kinh Truong
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            7 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: