Windows QPA: Improve reliability of clipboard retrieval
Clipboard retrieval sometimes fails due to the other application having the clipboard locked. Retry opening the clipboard. The choice of parameters is empirical, they have been observed to prevent failures for MS Office applications at least. Fixes: QTBUG-53979 Change-Id: Icbcaee149f0d377f33b222cdafbb2a21a7f1cf9d Reviewed-by: André de la Rocha <andre.rocha@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
parent
f7cb11d6f1
commit
ae7b218982
@ -115,12 +115,21 @@ static QDebug operator<<(QDebug d, const QMimeData *mimeData)
|
||||
|
||||
IDataObject *QWindowsClipboardRetrievalMimeData::retrieveDataObject() const
|
||||
{
|
||||
enum : int { attempts = 3 };
|
||||
IDataObject * pDataObj = nullptr;
|
||||
if (OleGetClipboard(&pDataObj) == S_OK) {
|
||||
if (QWindowsContext::verbose > 1)
|
||||
qCDebug(lcQpaMime) << __FUNCTION__ << pDataObj;
|
||||
return pDataObj;
|
||||
// QTBUG-53979, retry in case the other application has clipboard locked
|
||||
for (int i = 1; i <= attempts; ++i) {
|
||||
if (SUCCEEDED(OleGetClipboard(&pDataObj))) {
|
||||
if (QWindowsContext::verbose > 1)
|
||||
qCDebug(lcQpaMime) << __FUNCTION__ << pDataObj;
|
||||
return pDataObj;
|
||||
}
|
||||
qCWarning(lcQpaMime, i == attempts
|
||||
? "Unable to obtain clipboard."
|
||||
: "Retrying to obtain clipboard.");
|
||||
QThread::msleep(50);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user