From 660a43ecf4c2a7440259fc6589bf3aaee86a9f32 Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Fri, 29 Apr 2016 21:51:39 +0100 Subject: [PATCH] Clipboard: Retry on_dataChanged() after a delay on windows (#10109) An undocumented behaviour of QClipboard::mimeData() is that it can fail on windows due to the specificities of the windows API that allow a race condition. In particular it seems that querying the clipboard as soon as the dataChanged() signal is received favourises this race condition. Thanks to Trac user bquistorff for the explanation and a proof of concept patch. --- src/frontends/qt4/GuiClipboard.cpp | 13 ++++++++++++- src/frontends/qt4/GuiClipboard.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/frontends/qt4/GuiClipboard.cpp b/src/frontends/qt4/GuiClipboard.cpp index 1de945ed8e..e4ec95460c 100644 --- a/src/frontends/qt4/GuiClipboard.cpp +++ b/src/frontends/qt4/GuiClipboard.cpp @@ -112,7 +112,7 @@ GuiClipboard::GuiClipboard() connect(qApp->clipboard(), SIGNAL(dataChanged()), this, SLOT(on_dataChanged())); // initialize clipboard status. - on_dataChanged(); + update(); } @@ -550,6 +550,17 @@ bool GuiClipboard::hasInternal() const void GuiClipboard::on_dataChanged() +{ + update(); +#if defined(Q_OS_WIN) || defined(Q_CYGWIN_WIN) + // Retry on Windows (#10109) + if (cache_.formats().count() == 0) { + QTimer::singleShot(100, this, SLOT(update())); + } +#endif +} + +void GuiClipboard::update() { //Note: we do not really need to run cache_.update() unless the //data has been changed *and* the GuiClipboard has been queried. diff --git a/src/frontends/qt4/GuiClipboard.h b/src/frontends/qt4/GuiClipboard.h index b0805983c6..9e9ae7b43f 100644 --- a/src/frontends/qt4/GuiClipboard.h +++ b/src/frontends/qt4/GuiClipboard.h @@ -84,6 +84,7 @@ public: private Q_SLOTS: void on_dataChanged(); + void update(); private: bool plaintext_clipboard_empty_; -- 2.39.2