fix: use QClipboard properly in QClipboardProxy

- constructor with connection was never called
- `textChanged` was never emitted
- `clipboard` member was uninitialized
This commit is contained in:
Patryk Osmaczko 2022-11-24 15:42:45 +01:00 committed by Michał
parent 23c13fd738
commit 496cdd0645
2 changed files with 7 additions and 15 deletions

View File

@ -1,24 +1,20 @@
#ifndef QCLIPBOARDPROXY_HPP #pragma once
#define QCLIPBOARDPROXY_HPP
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QQmlEngine> #include <QQmlEngine>
#include <QJSEngine> #include <QJSEngine>
class QClipboard;
class QClipboardProxy : public QObject class QClipboardProxy : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(QClipboardProxy) Q_DISABLE_COPY(QClipboardProxy)
Q_PROPERTY(QString text READ text NOTIFY textChanged) Q_PROPERTY(QString text READ text NOTIFY textChanged)
QClipboardProxy() {} QClipboardProxy();
public: public:
explicit QClipboardProxy(QClipboard*);
QString text() const; QString text() const;
static QObject *qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine) static QObject *qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine)
@ -31,9 +27,4 @@ public:
signals: signals:
void textChanged(); void textChanged();
private:
QClipboard* clipboard;
}; };
#endif // QCLIPBOARDPROXY_HPP

View File

@ -1,13 +1,14 @@
#include "DOtherSide/Status/QClipboardProxy.h" #include "DOtherSide/Status/QClipboardProxy.h"
#include <QGuiApplication>
#include <QClipboard> #include <QClipboard>
QClipboardProxy::QClipboardProxy(QClipboard* c) : clipboard(c) QClipboardProxy::QClipboardProxy()
{ {
QObject::connect(c, SIGNAL (dataChanged()), this, SLOT(textChanged())); connect(QGuiApplication::clipboard(), &QClipboard::dataChanged, this, &QClipboardProxy::textChanged);
} }
QString QClipboardProxy::text() const QString QClipboardProxy::text() const
{ {
return clipboard->text(); return QGuiApplication::clipboard()->text();
} }