mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Make sure the clipboard is cleared before the QApplication instance is destroyed.
Also add safety check so we don't try to use the clipboard if it's not available.
This commit is contained in:
parent
013a924e43
commit
6e206704f9
@ -36,13 +36,7 @@ Clipboard::Clipboard(QObject* parent)
|
||||
{
|
||||
m_timer->setSingleShot(true);
|
||||
connect(m_timer, SIGNAL(timeout()), SLOT(clearClipboard()));
|
||||
}
|
||||
|
||||
Clipboard::~Clipboard()
|
||||
{
|
||||
if (m_timer->isActive()) {
|
||||
clearClipboard();
|
||||
}
|
||||
connect(qApp, SIGNAL(aboutToQuit()), SLOT(cleanup()));
|
||||
}
|
||||
|
||||
void Clipboard::setText(const QString& text)
|
||||
@ -66,6 +60,11 @@ void Clipboard::clearClipboard()
|
||||
{
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
|
||||
if (!clipboard) {
|
||||
qWarning("Unable to access the clipboard.");
|
||||
return;
|
||||
}
|
||||
|
||||
clipboard->clear(QClipboard::Clipboard);
|
||||
if (clipboard->supportsSelection()) {
|
||||
clipboard->clear(QClipboard::Selection);
|
||||
@ -77,6 +76,14 @@ void Clipboard::clearClipboard()
|
||||
#endif
|
||||
}
|
||||
|
||||
void Clipboard::cleanup()
|
||||
{
|
||||
if (m_timer->isActive()) {
|
||||
m_timer->stop();
|
||||
clearClipboard();
|
||||
}
|
||||
}
|
||||
|
||||
Clipboard* Clipboard::instance()
|
||||
{
|
||||
if (!m_instance) {
|
||||
|
@ -29,13 +29,13 @@ class Clipboard : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
~Clipboard();
|
||||
void setText(const QString& text);
|
||||
|
||||
static Clipboard* instance();
|
||||
|
||||
private Q_SLOTS:
|
||||
void clearClipboard();
|
||||
void cleanup();
|
||||
|
||||
private:
|
||||
explicit Clipboard(QObject* parent = Q_NULLPTR);
|
||||
|
Loading…
Reference in New Issue
Block a user