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. QWebSockets Sending messages with escaped characters and QLineEdit Inputs
QtWS25 Last Chance

QWebSockets Sending messages with escaped characters and QLineEdit Inputs

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 295 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.
  • O Offline
    O Offline
    Ollie_A
    wrote on last edited by
    #1

    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?

    JonBJ 1 Reply Last reply
    0
    • O Ollie_A

      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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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
      4
      • O Offline
        O Offline
        Ollie_A
        wrote on last edited by
        #3

        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
        0

        • Login

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