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

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.
  • Please_Help_me_DP Offline
    Please_Help_me_DP Offline
    Please_Help_me_D
    wrote on 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
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on 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/

      Please_Help_me_DP 1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on 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
        • jeremy_kJ jeremy_k

          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

          Please_Help_me_DP Offline
          Please_Help_me_DP Offline
          Please_Help_me_D
          wrote on last edited by
          #4

          @jeremy_k @mrjj thank you!

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on 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

            • Login

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