Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QWebSockets Sending messages with escaped characters and QLineEdit Inputs

    General and Desktop
    2
    3
    139
    Loading More Posts
    • 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.
    • O
      Ollie_A last edited by

      Hi all, I'm currently developing a client that connects to a server via websockets with a message protocol that requires the use of escaped characters such as \n and \r, and also quotations (""). As I'm using QT, I decided to use QtWebSockets, but I'm having two issues, those being the quotations and the escape characters. I can send a message such as CONNECT { "name": "ollie" } to the server, but this would be first stored as a QString before using WebSocketVariable.sendTextMessage(QStringVariable). To do this, I would need to escape the quotations such that CONNECT { "name": "ollie" } becomes Qstring val = "CONNECT { \"name\": \"ollie\" }";. This, however, when being sent to the server will send with the backslashes, which it can't handle.

      The other issue, along similar lines, is \r and \n (\r\n is used to represent the end of a message). The problem is these are input from an input box (QLineEdit) into a QString and become \\r and \\n, which does not work for the server. I've come up with a hack of replacing the \r with \r and \n with \n, But I'd rather it just didn't change the string input.

      Any ideas how I can go about solving these issues?

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @Ollie_A last edited by JonB

        @Ollie_A
        I don't know this makes much sense if you don't show your actual code. For example, you state

        Qstring val = "CONNECT { \"name\": \"ollie\" }";. This, however, when being sent to the server will send with the backslashes, which it can't handle.

        No, it won't send any backslashes.

        There should be no issues pertaining to QWebSockets messages/QLineEdit inputs here.

        I wonder if your confusion is more to do with C++ literals, or similar.

        In any case, in view of your question please, please use backticks in your posts of code here. Single backtick at start and end of code if in-line, tripe backticks on line of their own before first line and after last line if code on its own lines....

        This is in-line code.

        This is standalone
        possibly multiline code
        
        1 Reply Last reply Reply Quote 4
        • O
          Ollie_A last edited by

          Hi Jon, Sorry for the late reply, I didn't see any come through; Yes I believe my confusion was to do with C++ literals.

          Thanks for the info on backticks to show code, I'll make sure to use that in the future when asking more questions!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post