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. u_char* to QDataStream and readDouble() in the stream
Forum Updated to NodeBB v4.3 + New Features

u_char* to QDataStream and readDouble() in the stream

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 965 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.
  • Z Offline
    Z Offline
    zwokaros
    wrote on last edited by
    #1

    Hello

    I'm trying to parse TCP Packets that comes in the form of u_char*

    But I haven't found a way to do it

    What I'm looking for is the same behavior as stream.readDouble() in c# so that I can parse different values from the packets without iterating through the u_char*

    To be more specific I'll give an example of the data I want to parse

    This is the packet with like multiple values in it [int][utf text][double][u_short]

    And I want something like

    int i = stream.readInt();
    char *text = stream.readUTF8();
    double number = stream.readDouble();
    u_short tinyNumber = stream.readUShort();
    

    Is this possible?

    jsulmJ 1 Reply Last reply
    0
    • Z zwokaros

      Hello

      I'm trying to parse TCP Packets that comes in the form of u_char*

      But I haven't found a way to do it

      What I'm looking for is the same behavior as stream.readDouble() in c# so that I can parse different values from the packets without iterating through the u_char*

      To be more specific I'll give an example of the data I want to parse

      This is the packet with like multiple values in it [int][utf text][double][u_short]

      And I want something like

      int i = stream.readInt();
      char *text = stream.readUTF8();
      double number = stream.readDouble();
      u_short tinyNumber = stream.readUShort();
      

      Is this possible?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @zwokaros Take a look at http://doc.qt.io/qt-5/qdatastream.html
      What type is stream?
      Assuming stream is QDataStream:

      int i;
      QString text;
      double number;
      u_short tinyNumber;
      stream >> i >> text >> number >> tinyNumber;
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Out of curiosity, where are these packets coming from ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          You can use @jsulm solution for all the types* apart for the text. You need to tell us how you can determine when the text finishes. Is it null terminated? does it have a header that tells you the size?

          * You should be careful with endianness but since you are saying it comes from TCP it's fair to assume the usual Big-Endian convention

          "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
          2

          • Login

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