diff --git a/scribus/scpaths.h b/scribus/scpaths.h
index e4f1f918b..90375f6bd 100644
--- a/scribus/scpaths.h
+++ b/scribus/scpaths.h
@@ -9,6 +9,8 @@ for which a new license (GPL+exception) is in place.
 
 #include <QString>
 #include <QStringList>
+#include <QTemporaryDir>
+#include <QLockFile>
 #include "scribusapi.h"
 
 class SCRIBUS_API ScPaths
@@ -95,6 +97,8 @@ public:
 	static QString scrapbookDir(bool createIfNotExists);
 	/** @brief Return path to directory used for temporary files*/
 	static QString tempFileDir();
+	/** @brief Cleanup temporary directories left behind by crashed Scribuses*/
+	static void cleanupTemp();
 	/** @brief Return path to directory used for downloaded (permanent) files*/
 	static QString downloadDir();
 	/** @brief Return path to Contents OSX subdirectory*/
@@ -116,6 +120,18 @@ protected:
 	/** @brief Pointer to existing instance of ScPaths, if any. */
 	static ScPaths* m_instance;
 
+	/*** The lockFile is used to tell if tempDir is in use */
+	static QLockFile lockFile;
+	static const QString lockFilename;
+
+	/*** The initializer makes sure that the file is locked as early as possible */
+	static char lockFileInitializer;
+	static char doLockFile();
+
+	/*** The temporary directory is used for temporary files */
+	static const QTemporaryDir tempDir;
+	static const QString tempDirPrefix;
+
 	// Members to hold system paths
 	QString m_docDir;
 	QString m_fontDir;
diff --git a/scribus/scpaths.cpp b/scribus/scpaths.cpp
index 18401c76d..d7cfbf7bb 100644
--- a/scribus/scpaths.cpp
+++ b/scribus/scpaths.cpp
@@ -10,6 +10,7 @@ for which a new license (GPL+exception) is in place.
 #include <QDir>
 #include <QProcess>
 #include <QStandardPaths>
+#include <QLockFile>
 
 #include "prefsmanager.h"
 #include "scconfig.h"
@@ -33,6 +34,13 @@ const char ScPaths::envPathSeparator = ';';
 const char ScPaths::envPathSeparator = ':';
 #endif
 
+// ScPaths::tempDir and the things needed for cleanupTempDir
+const QString ScPaths::lockFilename = "Scribus.lock";
+const QString ScPaths::tempDirPrefix = "Scribus-temp-";
+const QTemporaryDir ScPaths::tempDir { QTemporaryDir (tempDirPrefix + "XXXXXX") };
+QLockFile ScPaths::lockFile{ tempDir.path() + "/" + lockFilename };
+char ScPaths::lockFileInitializer {ScPaths::doLockFile()};
+
 // Init the singleton's "self" address to nullptr
 ScPaths* ScPaths::m_instance = nullptr;
 
@@ -664,26 +672,40 @@ QString ScPaths::scrapbookDir(bool createIfNotExists)
 
 QString ScPaths::tempFileDir()
 {
-#ifdef Q_OS_WIN32
-	QString tempPath;
-	WCHAR wTempPath[1024];
-	DWORD result = GetTempPathW(1024, wTempPath);
-	if (result)
+	return tempDir.path() + '/';
+}
+
+char ScPaths::doLockFile()
+{
+	// Lock as long as this Scribus runs.
+	lockFile.setStaleLockTime(0);
+
+	// The values are never used.
+	// This is just to lock the file as early as possible
+	// so no other Scribus cleans up this Scribuses tempDir
+	return ScPaths::lockFile.tryLock(500) ? '1' : '0';
+};
+
+void ScPaths::cleanupTemp()
+{
+	QDir tempDirOneUp(tempDir.path());
+	tempDirOneUp.cdUp();
+	QStringList searchFor(tempDirPrefix + "*");
+	QStringList scribusTempDirs(tempDirOneUp.entryList(searchFor));
+	for (QString tmpDirName : scribusTempDirs)
 	{
-		tempPath = QString::fromUtf16((const unsigned short*) wTempPath);
-		tempPath.replace('\\', '/');
-		tempPath += "/";
-		// GetTempPath may return Windows directory, better not use this one
-		// for temporary files
-		if (QDir(tempPath).exists() && tempPath != windowsSpecialDir(CSIDL_WINDOWS))
-			return tempPath;
+		QLockFile lockTester(tempDirOneUp.absolutePath() + "/" + tmpDirName + "/" + lockFilename);
+		lockTester.setStaleLockTime(500);
+		if (lockTester.tryLock())
+		{
+			// The lock is aquired.
+			// This means the Scribus that once used the temporary
+			// directory containing the lockfile is no longer running.
+			lockTester.unlock();
+			QDir deleteThis(tempDirOneUp.absolutePath() + "/" + tmpDirName);
+			deleteThis.removeRecursively();
+		}
 	}
-#endif
-
-	QDir tempAppDirectory(applicationDataDir() + "temp/");
-	if (!tempAppDirectory.exists())
-		tempAppDirectory.mkpath(tempAppDirectory.absolutePath());
-	return tempAppDirectory.absolutePath() + "/";
 }
 
 QString ScPaths::downloadDir()
diff --git a/scribus/scribusapp.cpp b/scribus/scribusapp.cpp
index db7ae2903..d61b67d29 100644
--- a/scribus/scribusapp.cpp
+++ b/scribus/scribusapp.cpp
@@ -107,6 +107,7 @@ ScribusQApp::~ScribusQApp()
 {
 	delete m_ScCore;
 	delete m_scDLMgr;
+	ScPaths::cleanupTemp();
 	LanguageManager::deleteInstance();
 }
 
