refs #144 Util class, deleting temp files when application shuts down. First used with soundgenerator's temp. wav-files

This commit is contained in:
Klaus Basan
2014-02-19 23:52:54 +01:00
parent 9d7bd68433
commit 7b1fa5617d
2 changed files with 52 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
#include <QFile>
#include "filedeleter.h"
namespace BlackMisc
{
CFileDeleter::~CFileDeleter()
{
foreach(const QString fn, this->m_fileNames)
{
QFile f(fn);
f.remove();
}
}
}

View File

@@ -0,0 +1,38 @@
#ifndef BLACKMISC_CFILEDELETER_H
#define BLACKMISC_CFILEDELETER_H
#include <QObject>
#include <QDebug>
namespace BlackMisc
{
/*!
* \brief Utility class, deleting files when it is destroyed
*/
class CFileDeleter : public QObject
{
Q_OBJECT
private:
QStringList m_fileNames;
public:
/*!
* \brief File deleter
* \param parent
*/
explicit CFileDeleter(QObject *parent = nullptr) : QObject(parent) {}
//! \brief add given file for deletion
void addFileForDeletion(const QString &file)
{
if (!this->m_fileNames.contains(file)) this->m_fileNames.append(file);
}
//! \brief Destructor
~CFileDeleter();
};
}
#endif // guard