How to deal with “%1” in the argument of QString::arg() ?

How to deal with “%1” in the argument of QString::arg() ?

Asked on January 10, 2019 in Qt.
Add Comment


  • 3 Answer(s)

    Deals with the argument of QString::arg():

    Just try this link   QString::arg():

    QString str;
    str = "%1 %2";
    str.arg("%1f", "Hello"); // returns "%1f Hello"
    
    Answered on January 10, 2019.
    Add Comment

    The initialized statement is :

    The arg() overload for multiple arguments and takes the  QString.  In arguments are QStrings, can  placeholders in the format string:

    QString("1%1 2%2 3%3 4%4").arg(int1).arg(string2).arg(string3).arg(int4);
    
    

    as long as:

    QString("1%1 2%3 3%4 4%2").arg(int1).arg(int4).arg(string2, string3);
    
    

    Here, first  all the string is  not replaced  and then  all the strings are replaced at the same time.

     

    Answered on January 10, 2019.
    Add Comment

    The alternative code is;

    QString("%1-%2").arg("%2","foo");
    
    
    Answered on January 10, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.