I connect a slot to the dataChanged signal of QClipboard to store the image in the clipboard to a variable mimedata(reference):
void MyWin::clipboardDataChanged()
{
foreach
(QString format, m
->formats
()) {
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);
}
}
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);
}
}
To copy to clipboard, switch view to plain text mode
And restore mimedata to clipboard as follows:
void MyWin::onrestore()
{
}
void MyWin::onrestore()
{
QApplication::clipboard()->setMimeData(mimedata);
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks