Results 1 to 3 of 3

Thread: Escaping %1 with QString::arg()

  1. #1
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Escaping %1 with QString::arg()

    Hi,

    I'm using QString::arg() to fill in data in a string.

    Unfortunately, my string contains also the text "%1" that must appear in the output unchanged.

    Is there a way to escape the %n when using .arg() ?

    Best regards,
    Marc

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Escaping %1 with QString::arg()

    Have you tried escaping the % character with another % character?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Escaping %1 with QString::arg()

    Something like this should work:
    Qt Code:
    1. for(int i =0; i <10; i++){
    2. qDebug() << QString("String % 1, no %1").arg(i).replace("% 1", "%1");
    3. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 8
    Last Post: 25th November 2010, 11:40
  2. With QString create a QString&
    By avis_phoenix in forum Newbie
    Replies: 1
    Last Post: 21st April 2010, 22:05
  3. Replies: 4
    Last Post: 1st February 2010, 14:21
  4. Replies: 4
    Last Post: 31st January 2008, 20:44
  5. how to copy part of QString to anothe QString
    By nass in forum Qt Programming
    Replies: 1
    Last Post: 26th March 2007, 19:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.