summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/io/qtemporaryfile.cpp44
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp4
2 files changed, 34 insertions, 14 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index 0855d93962..ad7d7e6e0f 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -364,6 +364,8 @@ protected:
QTemporaryFilePrivate();
~QTemporaryFilePrivate();
+ QString defaultTemplateName() const;
+
bool autoRemove;
QString templateName;
};
@@ -376,6 +378,18 @@ QTemporaryFilePrivate::~QTemporaryFilePrivate()
{
}
+QString QTemporaryFilePrivate::defaultTemplateName() const
+{
+ QString baseName;
+#if defined(QT_BUILD_CORE_LIB)
+ baseName = QCoreApplication::applicationName();
+ if (baseName.isEmpty())
+#endif
+ baseName = QLatin1String("qt_temp");
+
+ return QDir::tempPath() + QLatin1Char('/') + baseName + QLatin1String(".XXXXXX");
+}
+
//************* QTemporaryFile
/*!
@@ -409,11 +423,11 @@ QTemporaryFilePrivate::~QTemporaryFilePrivate()
returns an empty string before this.
A temporary file will have some static part of the name and some
- part that is calculated to be unique. The default filename \c
- qt_temp will be placed into the temporary path as returned by
- QDir::tempPath(). If you specify your own filename, a relative
- file path will not be placed in the temporary directory by
- default, but be relative to the current working directory.
+ part that is calculated to be unique. The default filename will be
+ determined from QCoreApplication::applicationName() (otherwise \c qt_temp) and will
+ be placed into the temporary path as returned by QDir::tempPath().
+ If you specify your own filename, a relative file path will not be placed in the
+ temporary directory by default, but be relative to the current working directory.
Specified filenames can contain the following template \c XXXXXX
(six upper case "X" characters), which will be replaced by the
@@ -429,7 +443,7 @@ QTemporaryFile::QTemporaryFile()
: QFile(*new QTemporaryFilePrivate)
{
Q_D(QTemporaryFile);
- d->templateName = QDir::tempPath() + QLatin1String("/qt_temp.XXXXXX");
+ d->templateName = d->defaultTemplateName();
}
QTemporaryFile::QTemporaryFile(const QString &templateName)
@@ -441,8 +455,10 @@ QTemporaryFile::QTemporaryFile(const QString &templateName)
#else
/*!
- Constructs a QTemporaryFile in QDir::tempPath(), using the file template
- "qt_temp.XXXXXX". The file is stored in the system's temporary directory.
+ Constructs a QTemporaryFile using as file template
+ the application name returned by QCoreApplication::applicationName()
+ (otherwise \c qt_temp) followed by ".XXXXXX".
+ The file is stored in the system's temporary directory, QDir::tempPath().
\sa setFileTemplate(), QDir::tempPath()
*/
@@ -450,7 +466,7 @@ QTemporaryFile::QTemporaryFile()
: QFile(*new QTemporaryFilePrivate, 0)
{
Q_D(QTemporaryFile);
- d->templateName = QDir::tempPath() + QLatin1String("/qt_temp.XXXXXX");
+ d->templateName = d->defaultTemplateName();
}
/*!
@@ -475,8 +491,10 @@ QTemporaryFile::QTemporaryFile(const QString &templateName)
}
/*!
- Constructs a QTemporaryFile (with the given \a parent) in
- QDir::tempPath(), using the file template "qt_temp.XXXXXX".
+ Constructs a QTemporaryFile (with the given \a parent)
+ using as file template the application name returned by QCoreApplication::applicationName()
+ (otherwise \c qt_temp) followed by ".XXXXXX".
+ The file is stored in the system's temporary directory, QDir::tempPath().
\sa setFileTemplate()
*/
@@ -484,7 +502,7 @@ QTemporaryFile::QTemporaryFile(QObject *parent)
: QFile(*new QTemporaryFilePrivate, parent)
{
Q_D(QTemporaryFile);
- d->templateName = QDir::tempPath() + QLatin1String("/qt_temp.XXXXXX");
+ d->templateName = d->defaultTemplateName();
}
/*!
@@ -586,7 +604,7 @@ QString QTemporaryFile::fileName() const
/*!
Returns the set file template. The default file template will be
- called qt_temp and be placed in QDir::tempPath().
+ called qcoreappname.XXXXXX and be placed in QDir::tempPath().
\sa setFileTemplate()
*/
diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
index 2edb93aee2..18b5cccaaf 100644
--- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -111,6 +111,7 @@ void tst_QTemporaryFile::initTestCase()
{
// For QTBUG_4796
QVERIFY(QDir("test-XXXXXX").exists() || QDir().mkdir("test-XXXXXX"));
+ QCoreApplication::setApplicationName("tst_qtemporaryfile");
}
void tst_QTemporaryFile::cleanupTestCase()
@@ -221,8 +222,9 @@ void tst_QTemporaryFile::fileName()
file.setAutoRemove(true);
file.open();
QString fileName = file.fileName();
+ QVERIFY2(fileName.contains("/tst_qtemporaryfile."), qPrintable(fileName));
QVERIFY(QFile::exists(fileName));
- // Get path to the temp file, whithout the file name.
+ // Get path to the temp file, without the file name.
QString absoluteFilePath = QFileInfo(fileName).absolutePath();
#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
absoluteFilePath = absoluteFilePath.toLower();