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. send UdpPacket with WriteDatagram
Qt 6.11 is out! See what's new in the release blog

send UdpPacket with WriteDatagram

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 2.1k 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.
  • A Offline
    A Offline
    Alexanov
    wrote on last edited by
    #1

    Hi
    I want to send UDP packet from start point in QByteArrays datagram with specific length , How can i set start point(int type) in WriteDatagram line code?

    //sample code
    QUdpSocket::writeDatagram(const QByteArray &datagram, const QHostAddress &host, quint16 port)
    
    
    K 1 Reply Last reply
    0
    • A Alexanov

      Hi
      I want to send UDP packet from start point in QByteArrays datagram with specific length , How can i set start point(int type) in WriteDatagram line code?

      //sample code
      QUdpSocket::writeDatagram(const QByteArray &datagram, const QHostAddress &host, quint16 port)
      
      
      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @Alexanov

      You can't. There is writeDatagram for this.
      Or you use QByteArray::mid

      Vote the answer(s) that helped you to solve your issue(s)

      A 1 Reply Last reply
      2
      • K koahnig

        @Alexanov

        You can't. There is writeDatagram for this.
        Or you use QByteArray::mid

        A Offline
        A Offline
        Alexanov
        wrote on last edited by Alexanov
        #3

        @koahnig
        can you say me how can use WriteDatagram to specify start point?

        K 1 Reply Last reply
        0
        • A Alexanov

          @koahnig
          can you say me how can use WriteDatagram to specify start point?

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @Alexanov

          How do you define your starting point?

          one could be as folows when your starting point is after 10 bytes.

          QUdpSocket *udp;
          ...
          
          
          udp->writeDatagram ( bytearray.mid ( 10 ), address, port ); 
          

          also you can get a number of byte out of the byte array by

          QByteArray shorterArray = ba.mid ( 10, 12 );
          

          This would extract 12 bytes starting after the 10th byte of ba. With

          udp->writeDatagram ( shorterArray, address, port ); 
          

          or you can do

          udp->writeDatagram ( ba.mid (10, 12), address, port ); 
          

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          4

          • Login

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