How to save the image in clipboard in variable and restore it to clipboard later?
I connect a slot to the dataChanged signal of QClipboard to store the image in the clipboard to a variable mimedata(reference):
Code:
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);
}
}
And restore mimedata to clipboard as follows:
Code:
void MyWin::onrestore()
{
}
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?
Re: How to save the image in clipboard in variable and restore it to clipboard later?
If you want inter-operability with non-Qt apps, like MS Paint, then you need to convert your image into one of the "standard" MIME types, like image/jpg or image/bmp. There is a complete list here. This will probably require saving your QImage into one of these image types before pasting it.
Re: How to save the image in clipboard in variable and restore it to clipboard later?
Quote:
Originally Posted by
d_stranz
If you want inter-operability with non-Qt apps, like MS Paint, then you need to convert your image into one of the "standard" MIME types, like image/jpg or image/bmp. There is a
complete list here. This will probably require saving your QImage into one of these image types before pasting it.
When I press the Print-Screen key to take a screenshot, the only format I got is "application/x-qt-image". I do not know what the standard mime is for the image in the clipboard, how can I convert to a standard mime type?