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. How to send QPixmap using QTcpSocket?
QtWS25 Last Chance

How to send QPixmap using QTcpSocket?

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

    Hello,
    I have client and server app. I would like to send QPixmap from client to server.

    My client code:

        auto pixmap = qApp->screens().at(0)->grabWindow(QDesktopWidget().winId());
        QByteArray byte;
        QBuffer buffer(&byte);
        buffer.open(QIODevice::WriteOnly);
        pixmap.save(&buffer, "PNG");
        qInfo()<<tcp->write(buffer.data());
        qInfo()<<tcp->errorString();
    

    This code above I execute every 1 seconds ( QTimer and timeout() signal ).

    And my server code:
    In newConnection slot:

    qInfo()<<"new Connection";
    QTcpSocket *socket = server->nextPendingConnection();   /// server is QTcpServer
    QByteArray byte = socket->readAll();
    qInfo()<<byte.size();
    QPixmap pixmap;
    if(pixmap.loadFrodData(byte, "PNG"))
    {
         label->setPixmap(pixmap);
    }
    socket->close();
    delete socket;
    

    On my server I see only one textes ( not every second - only once )
    "new Connection"
    0

    On my client I see:
    numbers like 380124
    "Unknown error"

    And I see that textes every 1 second

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You are closing the socket immediately so unless you reopen the connection each time, the error you see is normal.

      Next, you are using wrong expectations with your code. Unless your image is really small, you won't have all the data in one go like that on the other side.

      Take a look at the transaction part of a QDataStream.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

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