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. Sending image in blocks via datastream does not work for other block sizes??
Forum Updated to NodeBB v4.3 + New Features

Sending image in blocks via datastream does not work for other block sizes??

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 265 Views 2 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.
  • G Offline
    G Offline
    ganapathi
    wrote on last edited by
    #1

    Hi

    I am sending an image via network in blocks of 20 as shown below:

    sender.cpp file****
    Sender::Sender(int no)
    {
    socket = new QUdpSocket( this );
    a = 0;
    img_block = 0;
    block_size = 20;
    num = no;

    if(num == 1)
    image = new QImage("C:/Users/Public/Pictures/Sample Pictures/Desert.jpg" );
    

    if( image->isNull() )
    qDebug() << "Failed to open test.jpg" ;
    QTimer *timer = new QTimer( this );

    timer->isSingleShot();
      QTimer::singleShot(1000, this, SLOT(broadcastLine()) );
      connect( this, SIGNAL(done()), this, SLOT(broadcastLine()) );
    

    }

    void Sender::broadcastLine()
    {

    QByteArray buffer( block_size+3*image->width(), 0 );
    QDataStream stream( &buffer, QIODevice::WriteOnly );
    stream.setVersion( QDataStream::Qt_5_5 );

    stream << (quint16)image->width() << (quint16)image->height();

    stream << img_block;

      for( int x=0; x<image->width(); ++x )
      {
                for(int y=block_size*a; y <block_size+(block_size*a);y++)
          {
    
              if( y < image->height())
              {
               QRgb rgb = image->pixel( x, y );
               stream << (quint8)qRed( rgb ) << (quint8)qGreen( rgb ) << (quint8)qBlue( rgb );
              }
              else
              {
                  img_block = y = a = 0;
                  img_block = -block_size;
              }
          }
      }
    
    
    if(num==1)
     socket->writeDatagram( buffer, QHostAddress::Broadcast,9988 );
    

    img_block = img_block + block_size;
    a++;

     emit done();
    

    }

    The above program works for block_size< 20 but not for 32 which I am interested. I dont have even the slightest idea of whats happening and even how to debug this?

    Regards

    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