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. Transferring images over qudpsocket in qt
Forum Updated to NodeBB v4.3 + New Features

Transferring images over qudpsocket in qt

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.3k 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.
  • S Offline
    S Offline
    sarahjohn
    wrote on last edited by
    #1

    Hi,
    I am trying to send an image file over qudpsocket.The code I used to send a cpp file is given below.8388 is the size of the file.
    @ QFile file1("/home/test.cpp");
    QByteArray bytes;
    file1.open(QIODevice::ReadOnly);
    QTextStream in(&file1);
    bytes = in.read(8838).toLatin1();
    socket->writeDatagram(bytes, QHostAddress::Broadcast,9988);@

    and I received the file using the code give below.

           @QFile file("received.txt");
           file.resize(0);
           file.open(QIODevice::Append);
           QTextStream out(&file);
                   QByteArray data;
                   data.resize(socket->pendingDatagramSize());
                   socket->readDatagram(data.data(),data.size());
                   QString str=data.data();
                    out << data;@
    

    How ever when I transmit an jpeg file like this.How to get the image file to Qdatastream and send like this easily and receive at the client end..Pleas help

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      It all about serializing your binary file in to byte-array and passing it.
      Try this

      @QImage img=QImage("my.JPG");
      QBuffer buffer;
      QImageWriter writer(&buffer, "JPQ");
      writer.write(img);
      QByteArray data;
      data.append( buffer.data() );
      socket->writeDatagram(data, QHostAddress::Broadcast,2000);@

      At service side also use the QDataStream to reach appropriately. I have not tried.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      1
      • S Offline
        S Offline
        sarahjohn
        wrote on last edited by
        #3

        thanks a lot.That was what I am searching for.

        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