summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qtemporaryfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qtemporaryfile.cpp')
-rw-r--r--src/corelib/io/qtemporaryfile.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index bdf4392275..e8e8d8c878 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -409,14 +409,24 @@ QTemporaryFilePrivate::~QTemporaryFilePrivate()
QAbstractFileEngine *QTemporaryFilePrivate::engine() const
{
if (!fileEngine) {
- if (fileName.isEmpty())
- fileEngine = new QTemporaryFileEngine(templateName, 0600);
- else
- fileEngine = new QTemporaryFileEngine(fileName, 0600, false);
+ fileEngine = new QTemporaryFileEngine;
+ resetFileEngine();
}
return fileEngine;
}
+void QTemporaryFilePrivate::resetFileEngine() const
+{
+ if (!fileEngine)
+ return;
+
+ QTemporaryFileEngine *tef = static_cast<QTemporaryFileEngine *>(fileEngine);
+ if (fileName.isEmpty())
+ tef->initialize(templateName, 0600);
+ else
+ tef->initialize(fileName, 0600, false);
+}
+
QString QTemporaryFilePrivate::defaultTemplateName()
{
QString baseName;
@@ -769,6 +779,13 @@ bool QTemporaryFile::open(OpenMode flags)
}
}
+ // reset the engine state so it creates a new, unique file name from the template;
+ // equivalent to:
+ // delete d->fileEngine;
+ // d->fileEngine = 0;
+ // d->engine();
+ d->resetFileEngine();
+
if (QFile::open(flags)) {
d->fileName = d->fileEngine->fileName(QAbstractFileEngine::DefaultName);
return true;