Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Decode QString str(R"RX(...)RX") and explain what it is
QtWS25 Last Chance

Decode QString str(R"RX(...)RX") and explain what it is

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Please_Help_me_D
    wrote on 27 Sept 2020, 01:42 last edited by
    #1

    Hi,

    I started to learn QRegularExpression and I needed to write something like:

    QString str("Quotes " are not allowed");
    

    but as you can see I cannot simply put quote symbol " to QString.
    But I can do it in the following way:

    QString str(R"(Quotes " are not allowed)");
    

    or:

    QString str(R"RX(Quotes " are not allowed)RX");
    

    Could someone explain what this R and RX mean in this case? How to google that?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jeremy_k
      wrote on 27 Sept 2020, 05:14 last edited by
      #2

      R""()"" is a C++ raw string literal. RX in the last example is used as a delimiter to avoid false detection of the end of the literal.

      https://en.cppreference.com/w/cpp/language/string_literal #6

      Asking a question about code? http://eel.is/iso-c++/testcase/

      P 1 Reply Last reply 27 Sept 2020, 11:41
      3
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 27 Sept 2020, 06:17 last edited by mrjj
        #3

        Hi
        As jeremy_k says it's a raw string literal which helps to avoid having to escape everything.
        Before they came along one has to write it as

            QString str("\"Quotes \" are not allowed");
        

        For regular expressions, this can fast becomes very clumsy and error-prone.

        1 Reply Last reply
        2
        • J jeremy_k
          27 Sept 2020, 05:14

          R""()"" is a C++ raw string literal. RX in the last example is used as a delimiter to avoid false detection of the end of the literal.

          https://en.cppreference.com/w/cpp/language/string_literal #6

          P Offline
          P Offline
          Please_Help_me_D
          wrote on 27 Sept 2020, 11:41 last edited by
          #4

          @jeremy_k @mrjj thank you!

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 27 Sept 2020, 16:52 last edited by
            #5

            Hi,

            Just in case, Qt provides a helper tool to help you write your regexps and test them.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            3

            1/5

            27 Sept 2020, 01:42

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved