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. How to insert a double quotes in a QString?

How to insert a double quotes in a QString?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 3.5k Views 2 Watching
  • 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.
  • veenusavV Offline
    veenusavV Offline
    veenusav
    wrote on last edited by veenusav
    #1

    Re: How to insert double quotes in the contents of a QString?
    The answer in the above thread is not understandable in C++ syntax. please help.
    My case is simple, I want Qt to avoid putting escape sequence in QString object. see this code.

    const char *s="dir=\"c:/Program Files\"";
    QString qs="dir=\"c:/Program Files\"";
    qDebug()<<s; // shows  dir="c:/Program Files"
    qDebug()<<qs;// shows  dir=\"c:/Program Files\"
    

    why qs added a back slash(or the escape sequence) ?

    aha_1980A 1 Reply Last reply
    0
    • veenusavV veenusav

      Re: How to insert double quotes in the contents of a QString?
      The answer in the above thread is not understandable in C++ syntax. please help.
      My case is simple, I want Qt to avoid putting escape sequence in QString object. see this code.

      const char *s="dir=\"c:/Program Files\"";
      QString qs="dir=\"c:/Program Files\"";
      qDebug()<<s; // shows  dir="c:/Program Files"
      qDebug()<<qs;// shows  dir=\"c:/Program Files\"
      

      why qs added a back slash(or the escape sequence) ?

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @veenusav said in How to insert a double quotes in a QString?:

      why qs added a back slash(or the escape sequence) ?

      It doesn't. Just look at qs in a debugger. For some reason, qDebug() escapes inline quotes (that may be intentional, haven't investigated).

      Qt has to stay free or it will die.

      kshegunovK 1 Reply Last reply
      5
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        QString is fine, it's just qDebug that forces the print of escape chars. Use qDebug().noquote() << qs;

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        10
        • veenusavV Offline
          veenusavV Offline
          veenusav
          wrote on last edited by
          #4

          wonderful. You guys almost answered within seconds!. thank you. so qDebug() made me confused. so I will continue work peacefully. good day to you.

          1 Reply Last reply
          0
          • aha_1980A aha_1980

            @veenusav said in How to insert a double quotes in a QString?:

            why qs added a back slash(or the escape sequence) ?

            It doesn't. Just look at qs in a debugger. For some reason, qDebug() escapes inline quotes (that may be intentional, haven't investigated).

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @aha_1980 said in How to insert a double quotes in a QString?:

            For some reason, qDebug() escapes inline quotes (that may be intentional, haven't investigated).

            It's intentional, yes. There was a discussion about it, I think on the mailing list, about a year ago or so, I can't seem to dig it up though. But as far as I remember Thiago was adamant this is intended and correct behavior.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            4

            • Login

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