Use a thread lock for Clipboard.qimage()
Prevents this: user paste image (image provider retrieves the clipboard image to show it as a thumbnail), and immediatly presses enter (retrieves the image to convert it and send to Python); the two calls would run at the same time instead of one waiting for the other to set the cache.
This commit is contained in:
parent
5cc1c55d95
commit
606fe3d022
|
@ -13,6 +13,8 @@
|
|||
#include <QIODevice>
|
||||
#include <QImage>
|
||||
#include <QMimeData>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
|
@ -47,6 +49,8 @@ public:
|
|||
}
|
||||
|
||||
QImage *qimage() {
|
||||
QMutexLocker locker(&(this->imageRetrievalLock));
|
||||
|
||||
if (this->cachedImage.isNull())
|
||||
this->cachedImage = this->clipboard->image();
|
||||
|
||||
|
@ -99,7 +103,8 @@ signals:
|
|||
|
||||
private:
|
||||
QClipboard *clipboard = QGuiApplication::clipboard();
|
||||
QImage cachedImage = QImage();
|
||||
QImage cachedImage = QImage();
|
||||
QMutex imageRetrievalLock;
|
||||
|
||||
void mainClipboardChanged() {
|
||||
this->contentChanged();
|
||||
|
|
Loading…
Reference in New Issue
Block a user