qtcentre2019
19th January 2020, 11:12
I connect a slot to the dataChanged signal of QClipboard to store the image in the clipboard to a variable mimedata(reference (https://stackoverflow.com/questions/13762140/proper-way-to-copy-a-qmimedata-object)):
void MyWin::clipboardDataChanged()
{
const QMimeData * m=QApplication::clipboard()->mimeData();
mimedata = new QMimeData();
foreach(QString format, m->formats())
{
QByteArray data = m->data(format);
if(format.startsWith("application/x-qt"))
{
int index1 = format.indexOf('"') + 1;
int index2 = format.indexOf('"', index1);
format = format.mid(index1, index2 - index1);
}
mimedata->setData(format, data);
}
}
And restore mimedata to clipboard as follows:
void MyWin::onrestore()
{
QApplication::clipboard()->setMimeData(mimedata);
}
However, the data set to the clipboard seems corrupted. If I paste from the clipboard to Paint, it says "The information on the Clipboard can't be inserted into Paint." I printed the format of the data in the clipboard, i.e., "application/x-qt-image". So I think it is not a format that is supported by other applications. Is this a bug of Qt?
void MyWin::clipboardDataChanged()
{
const QMimeData * m=QApplication::clipboard()->mimeData();
mimedata = new QMimeData();
foreach(QString format, m->formats())
{
QByteArray data = m->data(format);
if(format.startsWith("application/x-qt"))
{
int index1 = format.indexOf('"') + 1;
int index2 = format.indexOf('"', index1);
format = format.mid(index1, index2 - index1);
}
mimedata->setData(format, data);
}
}
And restore mimedata to clipboard as follows:
void MyWin::onrestore()
{
QApplication::clipboard()->setMimeData(mimedata);
}
However, the data set to the clipboard seems corrupted. If I paste from the clipboard to Paint, it says "The information on the Clipboard can't be inserted into Paint." I printed the format of the data in the clipboard, i.e., "application/x-qt-image". So I think it is not a format that is supported by other applications. Is this a bug of Qt?