Results 1 to 8 of 8

Thread: Using QString in evaluateJavaScript as agrument

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Using QString in evaluateJavaScript as agrument

    Qt Code:
    1. QString escapeJavascriptString(const QString & str)
    2. {
    3. QString out;
    4. QRegExp rx("(\\r|\\n|\\\\|\")");
    5. int pos = 0, lastPos = 0;
    6.  
    7. while ((pos = rx.indexIn(str, pos)) != -1)
    8. {
    9. out += str.mid(lastPos, pos - lastPos);
    10.  
    11. switch (rx.cap(1).at(0).unicode())
    12. {
    13. case '\r':
    14. out += "\\r";
    15. break;
    16. case '\n':
    17. out += "\\n";
    18. break;
    19. case '"':
    20. out += "\\\"";
    21. break;
    22. case '\\':
    23. out += "\\\\";
    24. break;
    25. }
    26. pos++;
    27. lastPos = pos;
    28. }
    29. out += str.mid(lastPos);
    30. return out;
    31. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jun 2010
    Posts
    6
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Symbian S60

    Default Re: Using QString in evaluateJavaScript as agrument

    Thanks for everyone.
    It worked.
    First, I need to escape with \\ and then others.

Similar Threads

  1. QWebElement::evaluateJavaScript strange behaviour
    By piotr.dobrogost in forum Qt Programming
    Replies: 3
    Last Post: 11th January 2011, 11:45
  2. Replies: 2
    Last Post: 16th June 2010, 15:42
  3. QWebFrame evaluateJavaScript
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 2nd September 2009, 07:55
  4. Problem with evaluateJavaScript()
    By piotr.dobrogost in forum Qt Programming
    Replies: 0
    Last Post: 26th August 2009, 19:36

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.