Why does Qt process clipboard data when pasted from the clipboard into an external program?

I do the following:

1) Copy the data to the clipboard in my Qt program on Windows.

QApplication::clipboard()->setText(data); 

2) Paste the data into an external program (notepad.exe). After that, my program starts processing the clipboard data. It calls special Windows methods:

 QWindowsOleDataObject::GetData(...); ... QWindowsMimeText::convertFromMime(...); 

This is a problem because when the size of the data in the clipboard is large, my program crashes when allocating memory in these methods.

I cannot understand this because the call stack is rather strange:

 qwindowsd.dll!QWindowsMimeText::convertFromMime(const tagFORMATETC & formatetc, const QMimeData * mimeData, tagSTGMEDIUM * pmedium) Line 606 C++ qwindowsd.dll!QWindowsOleDataObject::GetData(tagFORMATETC * pformatetc, tagSTGMEDIUM * pmedium) Line 144 C++ [External Code] Qt5Cored.dll!QEventDispatcherWin32::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags) Line 740 C++ qwindowsd.dll!QWindowsGuiEventDispatcher::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags) Line 73 C++ Qt5Cored.dll!QEventLoop::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags) Line 129 C++ Qt5Cored.dll!QEventLoop::exec(QFlags<enum QEventLoop::ProcessEventsFlag> flags) Line 204 C++ Qt5Cored.dll!QCoreApplication::exec() Line 1188 C++ Qt5Guid.dll!QGuiApplication::exec() Line 1508 C++ Qt5Widgetsd.dll!QApplication::exec() Line 2957 C++ main(int argc, char * * argv) Line 759 C++ 

This is some kind of internal work of Qt, I don’t know how to influence it.

+5
source share
1 answer

Qt can optimize the use of the "internal" clipboard. So QApplication::clipboard()->setText(data); doesn't actually copy data to the Windows clipboard - you can paste it inside the same Qt application, so copying to and from the Windows clipboard is not required. Only when using an external application does real copying occur.

Qt probably registers the OLE data provider as a “clipboard data source”, and Windows uses it when the clipboard data is needed in an external application.

So big data is in data from the start.

Sources: Qt clipboard implementation for Windows QWindowsClipboard uses: OleSetClipboard , which takes a pointer to a data source, not the file itself

+1
source

All Articles