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

Error with placeholder order in QString with arg

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 4.8.x, 5.2.0, 5.3.1, 5.4.0
    • None
    • Mac, Windows 7 64bit, MSVC2013 64bit, MSVC2013 32 bit, MVSV2010
    • 8481500f639e3d5e2259db57847a2e7068e30650

    Description

      If I reorder my “%”-placeholders in QString, arg can’t process them correctly. It seems like the first digit (0-9) of placeholder %2 gets eaten..
      Code below demonstrates the issue:

      void UnitTests::test_stringArgs()

      Unknown macro: { QString expected = QString("_Area52_"); QString test1 = QString("_%1%2%3_").arg("Area").arg(5).arg(2); QString test2 = QString("_%1_%3_%2_").arg("Area").arg(2).arg(5); QString test3 = QString("_%1%3%2_").arg("Area").arg(2); QString test4 = QString("_%1%3%2_").arg("Area").arg(2).arg(5); QCOMPARE(expected, test1); QCOMPARE(QString("_Area_5_2_"), test2); QCOMPARE(QString("_Area%32_"), test3); QCOMPARE(expected, test4); }

      FAIL! on line 13: test_stringArgs() Compared values are not the same
      Actual (expected): Area52
      Expected (test4): Area5

      QString test4 = QString("%1%3%2").arg("Area").arg(20).arg(50);
      QString test4m = QString("%1%2%3").arg("Area").arg(50).arg(20);
      Q_ASSERT (test4 == test4m);

      Assert fails due to:
      + test4 "Area500" QString
      + test4m "Area5020" QString@

      This happens on Qt 4.8.5 and Qt 5.2. People in the thread linked below describe other versions and platforms

      see thread on this issue: http://qt-project.org/forums/viewthread/52254/#215973

      Attachments

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

        Activity

          People

            laknoll Lars Knoll
            aalderweireldt Alexander Alderweireldt
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes