简体   繁体   中英

Can't paste very long clipboard text using QtClipboard on MacOS

We are using QClipboard to copy a csv text format, but when the text is long, there was nothing pasted.

We have a table with 400 columns, the csv text format of each row is 6600 characters.

If clipboard text is about 20k rows, the clipboard text can be pasted in other applications, such as Exel, Number. But if the number of rows is greater 20k rows, there is nothing is pasted.

Do you have any idea about this?

Memory information: Physical Memor: 8GB Memory Used: 4GB Cached Files: 982 MB Swap Used: 546 MB

Thank you

As far as I can tell, this problem appears to be a limitation of the applications you are pasting into. To investigate, I added the following lines to a Qt program:

QString oneLine;
for (int i=0; i<400; i++) oneLine += "123456789ABCDEF,";  // 400*16 == 6600
oneLine += '\n';

const int LINE_COUNT = 22000;
QString allLines;
for (int i=0; i<LINE_COUNT; i++) allLines += oneLine;

QClipboard * qc = qApp->clipboard();
qc->setText(allLines, QClipboard::Clipboard);

printf("SAVED %i bytes of data to clipboard!\n", allLines.size());

... then I ran the Qt program, then quit the program, and verified that pasting into Numbers (v12.1) had no effect. (as a control, I also tried it with LINE_COUNT set to eg 20,000 instead of 22,000, and verified that with that somewhat smaller data set, pasting the data into Numbers did work)

After that, I added the following lines to a different Qt program:

QClipboard * qc = qApp->clipboard();
QString t = qc->text();
printf("LOADED %i bytes from clipboard\n", t.size());
printf("Loaded data was:  [%s]\n", t.toUtf8().constData());

... and then when I run this second Qt program, I see it print out both the expected byte-count and the (very large,) amount of CSV-data that is present in the MacOS clipboard, as expected -- which indicates that the data did make it into the Mac Clipboard. which suggests that Numbers simply refused to process it, I was able to increase LINE_COUNT up to around 40,650 lines (aka 268,396,660 bytes) before the second Qt program could no longer see the clipboard-data (at 40,660 lines or higher. the Qt program says that the clipboard contains 0 bytes)

As for why the Qt->Qt clipboard transfer stops working at that size, I can't really say, although I suspect that the designers of the clipboard service (both at Apple and at Qt) never really intended it to be used for quite this much text at once. I do note that 268,396,660 is roughly 1/16th of (2^32-1), so it wouldn't surprise me if the text-data is being expanded eightfold at some point, and running into a signed-32-bit-counter overflow or something.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM