diff --git a/scribus/scpaths.cpp b/scribus/scpaths.cpp
index 18401c76d..076aaa85f 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,52 @@ 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() + '/';
+}
+/*
+    Make sure the lockfile is locked from the very beginning.
+    The lockfile is locked as long as Scribus is running.
+	It is used in cleanupTemp() to distinguish between tempDirs left 
+	behind by crashed Scribuses (unlocked) and tempDirs that are still in use (locked).
+*/
+char ScPaths::doLockFile()
+{
+	lockFile.setStaleLockTime(0);                          // Lock as long as this Scribus runs.
+	return ScPaths::lockFile.tryLock(500) ? '1' : '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
+
+
+/*
+	cleanup temporary directories leftover by crashed Scribuses.
+*/
+void ScPaths::cleanupTemp()
+
+{
+	QDir dir(tempDir.path());
+	dir.cdUp();
+	QStringList searchFor(tempDirPrefix + "*"); 
+	QString dbg1(dir.absolutePath());
+	
+	QStringList entries(dir.entryList(searchFor));
+	for (QString entry : entries)
 	{
-		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(dir.absolutePath() + "/" + entry + "/" + lockFilename);
+		lockTester.setStaleLockTime(500);   // 500ms seems really long but
+											// network storages should to be able to answer in time
+											// if this times out because the answer takes too long
+											// unused temp dirs will not get cleaned up
+											// and shutting down Scribus will take long
+		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(dir.absolutePath() + "/" + entry);
+			deleteThis.removeRecursively();
+		}
 	}
-#endif
-
-	QDir tempAppDirectory(applicationDataDir() + "temp/");
-	if (!tempAppDirectory.exists())
-		tempAppDirectory.mkpath(tempAppDirectory.absolutePath());
-	return tempAppDirectory.absolutePath() + "/";
 }
 
 QString ScPaths::downloadDir()
diff --git a/scribus/scpaths.h b/scribus/scpaths.h
index e4f1f918b..b5334b4da 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
@@ -31,6 +33,20 @@ public:
 	/*** The separator used between path list entries in environment variables */
 	static const char envPathSeparator;
 
+	
+	/* */
+	static const QString lockFilename;
+	static const QString tempDirPrefix;
+		
+	/*** The temporary directory is used for temporary files */
+	static const QTemporaryDir tempDir;
+
+	/*** The lockFile is used to tell if tempDir is in use */
+	static QLockFile lockFile;
+	/*** The initializer makes sure that the file is locked as early as possible */
+	static char lockFileInitializer;
+	static char doLockFile();
+	
 	/** @brief Return path to documentation directory */
 	const QString& docDir() const;
 	/** @brief Return path to icons directory*/
@@ -95,6 +111,8 @@ public:
 	static QString scrapbookDir(bool createIfNotExists);
 	/** @brief Return path to directory used for temporary files*/
 	static QString tempFileDir();
+	/** @brief to cleanup temporary directories leftover 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*/
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();
 }
 
