I'm using QClipboard in an application, where large 3D objects may be copied and pasted. The paste operations may block the GUI for some time as a lot of data has to be de-serialized.
I would like to optimize this for the frequent case where objects are copied and pasted on the same application window. In that case I do not need a system-wide clipboard, simple internal functions may store and copy the c++ object without need for deserialization.
So the idea is:
1)When "Copy" is called, a copy of the object is stored internally, and the object is serialized and placed on the system clipboard. A flag is set to remember that the next paste action should directly take the stored object, and not the system clipboard.
2)When the system clipboard has been modified by another app (possibly the same program, but another process), a flag is set to know that the next paste action should be done from the system clipboard, with deserialization.
3)The "Paste" action checks for the flag, and either take the internally stored object, or deserializes an object from the system clipboard.
The issue is 1). Whenever I change the system clipboard, the dataChanged() signal gets triggered. And this is done asynchronously, long time after QClipboard::setData has been called. So setting blockSignals() during the call to setData() does not help.
Any idea?
Thanks!
From the documentation I would assume that QClipboard::ownsClipboard()
returns true
if the dataChanged()
is caused by the current process itself.
So you could check that in the slot connected to dataChanged()
and e.g. ignore that specific invocation.