[Interest] Looks like a bug to me.

Tony Rietwyk tony at rightsoft.com.au
Sun Jun 4 16:41:34 CEST 2017


> Sent: Sunday, 4 June 2017 11:26 PM
> 
> Hello (No, this is not spam):
> 
> For me, the following:
> 
>    QString a = "XXX";
>    QString b = "";
>    QString c = "";
>    QString d = "1";
>    qDebug() << QString("A: %1%2%3%4") .arg(a) .arg(b) .arg(c) .arg(d);
>    qDebug() << QString("B: %4%1%2%3") .arg(b) .arg(c) .arg(d) .arg(a);
> 
> prints this:
> 
>    "A: XXX1"				# As expected.
>    "B: XXX"				# Expected: XXX1.
> 
> I think the 'B:' line demonstrates a bug.
> Where is the '1'?
> 
> Qt 5.7
> RedHat Enterprise Linux 6.8
> gcc: 4.9.3
> 
> Bill

Hi Bill, 

For the second one, consider that after arg(d) is executed, the input string to arg(a) is "B: %41".  Since 41 is now "the lowest numbered place marker", "XXX" gets substituted.  It is easy to mistakenly think that QString magically treats multiple .args as somehow being indexed.  I think the documentation for QString.arg should warn about your example, and the case when substituted strings contain %<number>. 

Regards, Tony





More information about the Interest mailing list