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

Incorrect handling of QString arg values combined with missing markers

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.9.5
    • None

    Description

      When using a string with arg markers (%1, %2 etc) and there is missing markers (ex: only %2) QString will incorrectly use the first arg instead of the second. For example,

      qDebug() << QString("Test-D %2").arg("foo").arg("bar")

      qDebug() << QString("Test-H %3 %3 %3").arg("foo").arg("bar")

      Will output "Test-D foo" instead of "Test-D bar" and "Test-H foo foo foo" instead of "Test-H %3 %3 %3"

      More complete list of working/not working examples follow:

      Test case #1: qDebug() << QString("Test-A %1 %2").arg("foo").arg("bar")
      Correct and expected output: Test-A foo bar

      Test case #2: qDebug() << QString("Test-B %2 %1").arg("foo").arg("bar")
      Correct and expected output: Test-B bar foo

      Test case #3: qDebug() << QString("Test-C %1").arg("foo").arg("bar")
      Correct and expected output: Test-C foo
      Diag message: QString::arg: Argument missing: Test-C foo, bar

      Test case #4: qDebug() << QString("Test-D %2").arg("foo").arg("bar")
      Expected Output: Test-D bar
      Incorrect output: Test-D foo
      Diag message: QString::arg: Argument missing: Test-D foo, bar

      Test case #5: qDebug() << QString("Test-E %3").arg("foo").arg("bar")
      Expected Output: Test-E
      Incorrect output: Test-E foo
      Diag message: QString::arg: Argument missing: Test-E foo, bar

      Test case #6: qDebug() << QString("Test-F %1 %2 %3").arg("foo").arg("bar")
      Correct and expected output: Test-F foo bar %3

      Test case #7: qDebug() << QString("Test-G %3 %1 %2").arg("foo").arg("bar")
      Correct and expected output: Test-G %3 foo bar

      Test case #8: qDebug() << QString("Test-H %3 %3 %3").arg("foo").arg("bar")
      Expected output: Test-H %3 %3 %3
      Incorrect output: Test-H foo foo foo
      Diag message: QString::arg: Argument missing: Test-H foo foo foo, bar

       

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            tcwilson tcwilson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes