Results 1 to 3 of 3

Thread: How could I revert back the escape char. in QLineEdit

  1. #1
    Join Date
    May 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How could I revert back the escape char. in QLineEdit

    Strings link "\n" "\t" and etc. will be input in the QLineEdit. "\\n" will be got from QLineEdit.text(), but I want to revert it back to "\n".

    One simple way is to use the replace function, QString.replace("\\n", "\n"), but it is only limited to some of the escape sequence.

    Escape sequence as "\x1b" can not be simply processed by replace function.

    Is there any way if I want to process all the escape sequence cases which are input from the QLineEdit?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How could I revert back the escape char. in QLineEdit

    One option is to iterate over the string with a regular expression:
    Qt Code:
    1. QString value = "\\x5cx21\\x21def\\x21ghi\\x23";
    2. const QRegExp re("\\\\x([0-9a-f]{2})");
    3. int pos = 0;
    4. while ((pos = re.indexIn(value, pos)) != -1) {
    5. bool ok;
    6. int v = re.cap(1).toInt(&ok, 16);
    7. value = value.replace(pos, 4, QChar(v));
    8. ++pos;
    9. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How could I revert back the escape char. in QLineEdit

    Quote Originally Posted by ChrisW67 View Post
    One option is to iterate over the string with a regular expression:
    Qt Code:
    1. QString value = "\\x5cx21\\x21def\\x21ghi\\x23";
    2. const QRegExp re("\\\\x([0-9a-f]{2})");
    3. int pos = 0;
    4. while ((pos = re.indexIn(value, pos)) != -1) {
    5. bool ok;
    6. int v = re.cap(1).toInt(&ok, 16);
    7. value = value.replace(pos, 4, QChar(v));
    8. ++pos;
    9. }
    To copy to clipboard, switch view to plain text mode 
    Thanks for your suggestion. But in this way, maybe I also have to deal with the Oct.mode as \033...

Similar Threads

  1. Replies: 2
    Last Post: 19th July 2013, 10:25
  2. Replies: 2
    Last Post: 8th October 2012, 11:27
  3. Replies: 1
    Last Post: 29th November 2010, 12:08
  4. Getting const char * from QLineEdit
    By squidge in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2009, 10:28
  5. QItemSelectionModel::currentChanged and revert change
    By Lykurg in forum Qt Programming
    Replies: 5
    Last Post: 25th March 2009, 08:48

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.