commit 660a43ecf4c2a7440259fc6589bf3aaee86a9f32
Author: Guillaume Munch <[email protected]>
Date:   Fri Apr 29 21:51:39 2016 +0100

    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.

diff --git a/src/frontends/qt4/GuiClipboard.cpp 
b/src/frontends/qt4/GuiClipboard.cpp
index 1de945e..e4ec954 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();
 }
 
 
@@ -551,6 +551,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.
        //However if run cache_.update() the moment a process grabs the
diff --git a/src/frontends/qt4/GuiClipboard.h b/src/frontends/qt4/GuiClipboard.h
index b080598..9e9ae7b 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_;

Reply via email to