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:
parent
23c13fd738
commit
496cdd0645
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue