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. [SOLVED] Double or single quoting: compiler dependent?
QtWS25 Last Chance

[SOLVED] Double or single quoting: compiler dependent?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 2 Posters 2.7k 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.
  • siropS Offline
    siropS Offline
    sirop
    wrote on last edited by sirop
    #1

    Hallo.

    I have a simple predefined string:

    pSender->sendTextMessage(QString("{\"action\":\"auth\",\"status\":\"error\",\"data\": {\"id\":3,\"msg\":\"Unknown user or incorrect password.\"}}") );
    

    As you might guess, it is about WebSocket programming.
    The problem I have is that when I compile with msvc2013,
    this message string is created and transmitted properly with all the double quotes at the right place:

    {"action":"auth","status":"error","data": {"id":3,"msg":"Unknown user or incorrect password."}}
    

    But when I compile with gcc version 4.9.1 (Ubuntu 4.9.1-16ubuntu6), I get this output
    on the client side:

    { action: 'auth',status: 'error',data: {id:'3', msg:'Unknown user or incorrect password.'} }
    

    As you see, the JSON tags have no quote signs at all and their values are single quoted
    which is not JSON standard.

    I read through http://stackoverflow.com/questions/21431633/does-g-meets-stdstring-c11-requirements. Do not know if I went astray with that...
    But on the other hand side: such a simple thing as quoting a string should be compiler dependent?

    So would updating to g++-5 solve the problem as this Stackoverflow link says:
    The other answers were correct at the time, but as of nowadays, accordingly to the GCC 5.x Change Log, libstdc++ as shipped by gcc 5 is now fully C++11 conformant.

    To be, or not to be: that is the question:
    Whether ’tis nobler in the mind to suffer
    The slings and arrows of outrageous fortune,
    Or to take arms against a sea of troubles,
    And by opposing end them?

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Just tried on Ubuntu with g++:

        std::cout << QString("{\"action\":\"auth\",\"status\":\"error\",\"data\": {\"id\":3,\"msg\":\"Unknown user or incorrect password.\"}}").toStdString();
        

        and got correct result.

        siropS 1 Reply Last reply
        0
        • jsulmJ jsulm

          Just tried on Ubuntu with g++:

          std::cout << QString("{\"action\":\"auth\",\"status\":\"error\",\"data\": {\"id\":3,\"msg\":\"Unknown user or incorrect password.\"}}").toStdString();
          

          and got correct result.

          siropS Offline
          siropS Offline
          sirop
          wrote on last edited by
          #4

          @jsulm

          Thanks for your reply.

          Can you tell me please which version of g++ you used?
          Was it 5.x ?

          To be, or not to be: that is the question:
          Whether ’tis nobler in the mind to suffer
          The slings and arrows of outrageous fortune,
          Or to take arms against a sea of troubles,
          And by opposing end them?

          1 Reply Last reply
          0
          • jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            g++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4

            siropS 1 Reply Last reply
            1
            • jsulmJ jsulm

              g++ (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4

              siropS Offline
              siropS Offline
              sirop
              wrote on last edited by
              #6

              @jsulm
              Thanks again.

              But what would you see if you try:

              qDebug () << QString("{\"action\":\"auth\",\"status\":\"error\",\"data\": {\"id\":3,\"msg\":\"Unknown user or incorrect password.\"}}"
              

              To be, or not to be: that is the question:
              Whether ’tis nobler in the mind to suffer
              The slings and arrows of outrageous fortune,
              Or to take arms against a sea of troubles,
              And by opposing end them?

              1 Reply Last reply
              0
              • jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                In this case I see:

                "{\"action\":\"auth\",\"status\":\"error\",\"data\": {\"id\":3,\"msg\":\"Unknown user or incorrect password.\"}}"
                
                siropS 1 Reply Last reply
                1
                • jsulmJ jsulm

                  In this case I see:

                  "{\"action\":\"auth\",\"status\":\"error\",\"data\": {\"id\":3,\"msg\":\"Unknown user or incorrect password.\"}}"
                  
                  siropS Offline
                  siropS Offline
                  sirop
                  wrote on last edited by
                  #8

                  @jsulm

                  Yes, seems to be something QWebSockets and compiler specific.
                  See http://code.woboq.org/qt5/qtwebsockets/src/websockets/qwebsocket_p.cpp.html#_ZN17QWebSocketPrivate15sendTextMessageERK7QString

                  qint64 QWebSocketPrivate::sendTextMessage(const QString &message)
                  {
                         return doWriteFrames(message.toUtf8(), false);
                  }
                  

                  And so on as doWriteFrames does coms char* conversion.

                  To be, or not to be: that is the question:
                  Whether ’tis nobler in the mind to suffer
                  The slings and arrows of outrageous fortune,
                  Or to take arms against a sea of troubles,
                  And by opposing end them?

                  1 Reply Last reply
                  0
                  • jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    toUtf8() returns a QByteArray, QByteArray::data() returns char*. if I do:

                    std::cout << QString("{\"action\":\"auth\",\"status\":\"error\",\"data\": {\"id\":3,\"msg\":\"Unknown user or incorrect password.\"}}").toUtf8().data();
                    

                    I still get the correct result.
                    I don't think it is a compiler issue (why should compiler remove " or replace them with ' ?).
                    How do you print out the string?

                    siropS 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      toUtf8() returns a QByteArray, QByteArray::data() returns char*. if I do:

                      std::cout << QString("{\"action\":\"auth\",\"status\":\"error\",\"data\": {\"id\":3,\"msg\":\"Unknown user or incorrect password.\"}}").toUtf8().data();
                      

                      I still get the correct result.
                      I don't think it is a compiler issue (why should compiler remove " or replace them with ' ?).
                      How do you print out the string?

                      siropS Offline
                      siropS Offline
                      sirop
                      wrote on last edited by sirop
                      #10

                      @jsulm said:

                      std::cout << QString("{"action":"auth","status":"error","data": {"id":3,"msg":"Unknown user or incorrect password."}}").toUtf8().data();

                      I set up this simple app:

                      #include <QCoreApplication>
                      #include <iostream>
                      
                      int main(int argc, char *argv[])
                      {
                          QCoreApplication a(argc, argv);
                          std::cout << QString("{\"action\":\"auth\",\"status\":\"error\",\"data\":{\"id\":3,\"msg\":\"Unknown user or incorrect password.\"}}").toUtf8().constData();
                          return a.exec();
                      }
                      

                      This works as it should with mingw51_x64 and msvc2013_x64 on Windows.

                      But with gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2) no output is printed out at all,
                      although it compiles without errors.

                      So if it is not a compiler issue then it is a compiler installation issue.

                      To be, or not to be: that is the question:
                      Whether ’tis nobler in the mind to suffer
                      The slings and arrows of outrageous fortune,
                      Or to take arms against a sea of troubles,
                      And by opposing end them?

                      1 Reply Last reply
                      0
                      • siropS Offline
                        siropS Offline
                        sirop
                        wrote on last edited by
                        #11

                        As always complicated problems have unexpectedly simple solutions.
                        Due to restricted user privileges I did not see the old chat server process
                        started by a colleague of mine.

                        So we were testing the old version all the time where the quoting issue
                        had not been yet dealt with.

                        To be, or not to be: that is the question:
                        Whether ’tis nobler in the mind to suffer
                        The slings and arrows of outrageous fortune,
                        Or to take arms against a sea of troubles,
                        And by opposing end them?

                        1 Reply Last reply
                        0

                        • Login

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