Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-73075

Timeout when get image data from clipboard

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.6.3, 5.9.7, 5.11.3, 5.12.0
    • None
    • All

    Description

      Copy a big image to clipboard, I can't get it in other application. The following code can reproduce this problem:

       

      // a.cpp
      #include <QGuiApplication>
      #include <QImage>
      #include <QClipboard>
      int main(int argc, char *argv[])
      
      { 
          QGuiApplication a(argc, argv);
          // If you load a more complex image, the size of the image pair can be reduced a lot. I tried using a jpg image with a size of 5613x3744, and I can get the same result.
          QImage image(20000, 20000, QImage::Format_ARGB32);
          image.fill(Qt::red);
          a.clipboard()->setImage(image);
          return a.exec();
       }
      

       

       

      // b.cpp
      #include <QGuiApplication> 
      #include <QImage> 
      #include <QClipboard>
      #include <QMimeData>
      #include <QtDebug>
      #include <QElapsedTimer>
      int main(int argc, char *argv[])
      {
          QGuiApplication a(argc, argv);
          QClipboard *b = a.clipboard();
          QObject::connect(b, &QClipboard::dataChanged, [b] { 
              QElapsedTimer et; 
              et.start();
              const QMimeData *data = b->mimeData();
              if (data->hasFormat("image/png")) { 
                   qint64 start = et.elapsed();
                   qDebug() << data->data("image/png").length();
                   qDebug() << et.elapsed() - start;
             }
      
         });
         return a.exec();
      }
      
      1. First start the application "b.cpp"
      2. Second start the applicatioin "a.cpp"

      I get the messages in "b.cpp":

      0
      5012
      

      Not only did not get the image data, and the application "b.cpp" was also blocked for 5 seconds.

      I found that the QXcbClipboard code has the "clipboard_timeout":
      https://github.com/qt/qtbase/blob/dev/src/plugins/platforms/xcb/qxcbclipboard.cpp#L222

      And
      https://github.com/qt/qtbase/blob/dev/src/plugins/platforms/xcb/qxcbclipboard.cpp#L901
      I guess "b.cpp" didn't get the image data because it waited for the clipboard event to time out. And see:  https://github.com/qt/qtbase/blob/dev/src/gui/kernel/qinternalmimedata.cpp#L222
      Because the image size is large, it takes a lot of time for "a.cpp" to encode QImage data into PNG format. Can provide encoding speed by reducing the compression ratio of PNG.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            liaqi Liang Qi
            zccrs JiDe Zhang
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change