Results 1 to 3 of 3

Thread: how to use qtcpsocket send qimage data

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2009
    Posts
    35
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Android

    Default how to use qtcpsocket send qimage data

    my tcpserver code
    Qt Code:
    1. void UserThread::sendData()
    2. {
    3. qDebug() << "sendData";
    4.  
    5. #ifdef TEST
    6. qDebug() << "TEST";
    7. QImage image("3.png");
    8.  
    9. qDebug() << image.byteCount() <<image.size();
    10. ba.append((char *)image.bits(),image.byteCount());
    11. qDebug() <<ba.size();
    12. this->m_tcpSocket->write(ba);
    13. if(!this->m_tcpSocket->waitForBytesWritten(-1))
    14. {
    15. qDebug() << "writen Bytes error " << this->m_tcpSocket->errorString();
    16. }
    17. this->m_tcpSocket->flush();
    18. #endif
    19. }
    To copy to clipboard, switch view to plain text mode 

    client code
    Qt Code:
    1. void MainWindow::readImage(){
    2. qDebug() << socket.bytesAvailable();
    3. ba = socket.readAll();
    4. socket.flush();
    5. qDebug() << ba.size();
    6. QImage image((uchar *)ba.data(),1024,768,QImage::Format_RGB32);
    7. ui->label->setPixmap(QPixmap::fromImage(image));
    8. }
    To copy to clipboard, switch view to plain text mode 

    my picture at attachment

    server read the picture sizse is 3145728

    but client recevie a wrong size
    i used flush
    but ...
    Attached Images Attached Images
    • File Type: jpg 3.jpg (69.1 KB, 38 views)

Similar Threads

  1. Replies: 4
    Last Post: 22nd March 2010, 18:32
  2. Send QImage over network
    By winston2020 in forum Qt Programming
    Replies: 5
    Last Post: 20th March 2009, 19:09
  3. How to send Pixmap through QTcpSocket?
    By live_07 in forum Qt Programming
    Replies: 1
    Last Post: 10th September 2008, 16:35
  4. Send Base64 encoded data
    By rmagro in forum Qt Programming
    Replies: 6
    Last Post: 29th October 2007, 16:58
  5. My client can't send data
    By hiuao in forum Qt Programming
    Replies: 10
    Last Post: 23rd February 2007, 09:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.