Fix QTimer cannot be stopped from another thread warning

This commit is contained in:
Aetf 2020-11-28 22:03:39 -05:00 committed by Jonathan White
parent 9a96124040
commit 30c2e39e70
2 changed files with 16 additions and 4 deletions

View File

@ -431,7 +431,7 @@ void Database::releaseData()
setEmitModified(false);
m_modified = false;
m_modifiedTimer.stop();
stopModifiedTimer();
s_uuidMap.remove(m_uuid);
m_uuid = QUuid();
@ -842,7 +842,7 @@ void Database::emptyRecycleBin()
void Database::setEmitModified(bool value)
{
if (m_emitModified && !value) {
m_modifiedTimer.stop();
stopModifiedTimer();
}
m_emitModified = value;
@ -863,7 +863,7 @@ void Database::markAsModified()
m_modified = true;
if (m_emitModified && !m_modifiedTimer.isActive()) {
// Small time delay prevents numerous consecutive saves due to repeated signals
m_modifiedTimer.start(150);
startModifiedTimer();
}
}
@ -871,7 +871,7 @@ void Database::markAsClean()
{
bool emitSignal = m_modified;
m_modified = false;
m_modifiedTimer.stop();
stopModifiedTimer();
m_hasNonDataChange = false;
if (emitSignal) {
emit databaseSaved();
@ -927,3 +927,13 @@ bool Database::changeKdf(const QSharedPointer<Kdf>& kdf)
return true;
}
void Database::startModifiedTimer()
{
QMetaObject::invokeMethod(&m_modifiedTimer, "start", Q_ARG(int, 150));
}
void Database::stopModifiedTimer()
{
QMetaObject::invokeMethod(&m_modifiedTimer, "stop");
}

View File

@ -202,6 +202,8 @@ private:
bool backupDatabase(const QString& filePath);
bool restoreDatabase(const QString& filePath);
bool performSave(const QString& filePath, QString* error, bool atomic, bool backup);
void startModifiedTimer();
void stopModifiedTimer();
QPointer<Metadata> const m_metadata;
DatabaseData m_data;