我做了以下的事情:
1)在Windows上的Qt程序中将数据复制到剪贴板。
QApplication::clipboard()->setText(data);
2)将数据粘贴到外部程序(notepad.exe)。 After that my program starts to process clipboard data. It calls Windows specific methods:
QWindowsOleDataObject::GetData(...); ... QWindowsMimeText::convertFromMime(...);
It is a problem, because when the size of data in clipboard is big my program fails on memory allocating in those methods.
I can't understand it because the call stack is quite 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++
It is some Qt internal work, I don't know how to impact on it.
Qt might optimize 'internal' clipboard usage. So QApplication::clipboard()->setText(data);
does not really copy data
to Windows clipboard – you might want to paste it inside same Qt application, so copying into Windows clipboard and back again is not necessary. Only when external application is used, real copying occurs.
Qt probably registers OLE data provider as 'clipboard data source' and Windows uses it when clipboard data is needed in external app.
So the big data is in data
from the beginning.
Sources: Qt Clipboard implementation for Windows QWindowsClipboard uses: OleSetClipboard , which accepts pointer to data source, not data itself