Fix binary data copying.

As the QClipboard::setMimeData documentation says, "Ownership of the
data is transferred to the clipboard." Allocate the mime data object
accordingly.

Note the results of trying to paste into hex editors on Windows.
Frhed works. Hex Editor Neo and HxD do not.

Change-Id: I46691ba95bf1f5c38817cd42ded73e8e67e4ee97
Reviewed-on: https://code.wireshark.org/review/9837
Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
Gerald Combs 2015-07-31 13:44:42 -07:00
parent 5336c9aabc
commit 26c933b8cc
1 changed files with 5 additions and 3 deletions

View File

@ -159,14 +159,16 @@ void ByteViewTab::copyBinary(const guint8 *data_p, int data_len)
QByteArray clipboard_bytes = QByteArray::fromRawData((const char *) data_p, data_len);
if (!clipboard_bytes.isEmpty()) {
QMimeData mime_data;
QMimeData *mime_data = new QMimeData;
// gtk/gui_utils.c:copy_binary_to_clipboard says:
/* XXX - this is not understood by most applications,
* but can be pasted into the better hex editors - is
* there something better that we can do?
*/
mime_data.setData("application/octet-stream", clipboard_bytes);
qApp->clipboard()->setMimeData(&mime_data);
// As of 2015-07-30, pasting into Frhed works on Windows. Pasting into
// Hex Editor Neo and HxD does not.
mime_data->setData("application/octet-stream", clipboard_bytes);
qApp->clipboard()->setMimeData(mime_data);
}
}