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. '\n' in QTcpSocket.write()
Qt 6.11 is out! See what's new in the release blog

'\n' in QTcpSocket.write()

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 349 Views 1 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.
  • N Offline
    N Offline
    NintyS
    wrote on last edited by
    #1

    Hello, I want to ask if there is a way to send string with '\n'? ( I don't want R"(string)", but if this is an only option then I will use it )

    JonBJ 1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by Kent-Dorfman
      #2

      There are many ways to do it. You have read the QIODevice class docs, right? and you understand that const char* or QByteArray& can be passed to Write()?

      After that it's just basic C/C++ programming.

      But the more important question is what EXACTLY do you really want to send, <CR>? <LF>? <CR><LF>?

      Streams based RFC protocols will specify exactly what they expect as an end-of-line sequence. Many text based protocols expect <CR><LF>.

      The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

      1 Reply Last reply
      3
      • N NintyS

        Hello, I want to ask if there is a way to send string with '\n'? ( I don't want R"(string)", but if this is an only option then I will use it )

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

        @NintyS
        There is no problem sending a newline (or any other character) via QTcpSocket.write(). If you do not want to write R"(string\n)" in your code you can always do it without the R literal string syntax via "string\\n". Or similarly as @Kent-Dorfman says if you need to send "string\\r\\n".

        1 Reply Last reply
        1

        • Login

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