Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.6.3, 5.9.7, 5.11.3, 5.12.0
-
None
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(); }
- First start the application "b.cpp"
- 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
Gerrit Reviews
For Gerrit Dashboard: QTBUG-73075 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
359073,1 | xcb: try often for every QXcbClipboard::waitForClipboardEvent() | dev | qt/qtbase | Status: NEW | 0 | 0 |
250073,5 | fix: clipboard encoding png image data timeout | dev | qt/qtbase | Status: ABANDONED | 0 | 0 |