]> git.lyx.org Git - features.git/commitdiff
Clipboard: Retry on_dataChanged() after a delay on windows (#10109)
authorGuillaume Munch <gm@lyx.org>
Fri, 29 Apr 2016 20:51:39 +0000 (21:51 +0100)
committerGuillaume Munch <gm@lyx.org>
Wed, 4 May 2016 18:20:56 +0000 (19:20 +0100)
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
src/frontends/qt4/GuiClipboard.h

index 1de945ed8e8ee99cc568da5daa122ad558e9aaf3..e4ec95460c9ddbfa5087edd4471d3c90f8cb2777 100644 (file)
@@ -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.
index b0805983c6ae0edc598a8d241e30d848d42113da..9e9ae7b43f8ccbfc8f07610654b13ecb0f50f586 100644 (file)
@@ -84,6 +84,7 @@ public:
 
 private Q_SLOTS:
        void on_dataChanged();
+       void update();
 
 private:
        bool plaintext_clipboard_empty_;