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. ByteArray to Image
Qt 6.11 is out! See what's new in the release blog

ByteArray to Image

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

    Hello Friends

    i am working on TCP/IP Application
    I am sending image using QTcpSocket and receive image in server Side application

    i am getting bytearray data from socket now i want to convert my bytearray Data into image

    My Server Side Code Is :

                        socket = reinterpret_cast<QTcpSocket*>(sender());                    
                        socket->setReadBufferSize(4096);                                                           
                        QFile target;                    
                        target.setFileName(QString("ABC.bmp"));                                                                
                        qDebug() << socket->readBufferSize();                    
                        qDebug() << socket->readAll();                    
                        Data = socket->readAll();                                                          
                        if (!target.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::ReadWrite))                    
                        {                    
                            qDebug() << "Can't open file for written";                    
                            return;                    
                        }                                                            
                        target.write(Data);                    
                        target.close();                                                          
                        ui->lbl_Image_From_Client->setPixmap(QPixmap("ABC.bmp"));                    
                        ui->lbl_Image_From_Client->update();
    

    My Client Side Code Is :

                                 if(socket->isOpen())                               
                                 {                                                                                            
                                    QFile file("Screen.bmp");                               
                                    if(!file.open(QIODevice::ReadWrite))                               
                                        qDebug() << "Can't Send";                               
                                    Data = file.readAll();                                      
                                    socket->setReadBufferSize(4096);                               
                                    socket->write(Data);                               
                                    qDebug() << socket->readAll();                               
                                    socket->flush();                               
                                 }
    

    i didn't get image at server side
    please help me to solve this problem

    jsulmJ 1 Reply Last reply
    0
    • Ketan__Patel__0011K Ketan__Patel__0011

      Hello Friends

      i am working on TCP/IP Application
      I am sending image using QTcpSocket and receive image in server Side application

      i am getting bytearray data from socket now i want to convert my bytearray Data into image

      My Server Side Code Is :

                          socket = reinterpret_cast<QTcpSocket*>(sender());                    
                          socket->setReadBufferSize(4096);                                                           
                          QFile target;                    
                          target.setFileName(QString("ABC.bmp"));                                                                
                          qDebug() << socket->readBufferSize();                    
                          qDebug() << socket->readAll();                    
                          Data = socket->readAll();                                                          
                          if (!target.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::ReadWrite))                    
                          {                    
                              qDebug() << "Can't open file for written";                    
                              return;                    
                          }                                                            
                          target.write(Data);                    
                          target.close();                                                          
                          ui->lbl_Image_From_Client->setPixmap(QPixmap("ABC.bmp"));                    
                          ui->lbl_Image_From_Client->update();
      

      My Client Side Code Is :

                                   if(socket->isOpen())                               
                                   {                                                                                            
                                      QFile file("Screen.bmp");                               
                                      if(!file.open(QIODevice::ReadWrite))                               
                                          qDebug() << "Can't Send";                               
                                      Data = file.readAll();                                      
                                      socket->setReadBufferSize(4096);                               
                                      socket->write(Data);                               
                                      qDebug() << socket->readAll();                               
                                      socket->flush();                               
                                   }
      

      i didn't get image at server side
      please help me to solve this problem

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

      @Ketan__Patel__0011 Your server code (did not check your client code) is not going to work if it is in a slot connected to readyRead signal (please post more complete code, so it is clear where that code chunk is actually located). The problem is: the data will arrive in several chunks not just one. That means you need to accumulate the data in a buffer until you got whole data and only then use it to create the image.

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

      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