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

View File

@ -1,13 +1,14 @@
#include "DOtherSide/Status/QClipboardProxy.h"
#include <QGuiApplication>
#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
{
return clipboard->text();
return QGuiApplication::clipboard()->text();
}