summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-05-18 12:58:44 (GMT)
committerJoão Abecasis <joao@abecasis.name>2009-05-22 12:33:45 (GMT)
commitf1793cbff8aa9b4adcb5fd511e495f7e96811e2b (patch)
tree9d79221828ffe31ea252353b38d213c45ad5fbde
parent5cb1ed45ba55dbc9752e0f6f47cc6d1525464646 (diff)
downloadQt-f1793cbff8aa9b4adcb5fd511e495f7e96811e2b.zip
Qt-f1793cbff8aa9b4adcb5fd511e495f7e96811e2b.tar.gz
Qt-f1793cbff8aa9b4adcb5fd511e495f7e96811e2b.tar.bz2
Unconditionally open temporary files in ReadWrite mode
Although QTemporaryFile hides QFile::open(OpenMode), this function is still available when accessing instance methods through the base class. Unconditionally setting ReadWrite allows the temporary file to be re-opened with different flags. Task-number: 248223 Reviewed-by: Thiago
-rw-r--r--src/corelib/io/qtemporaryfile.cpp1
-rw-r--r--tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp15
2 files changed, 16 insertions, 0 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index b6eff94..3f8f978 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -720,6 +720,7 @@ bool QTemporaryFile::open(OpenMode flags)
return true;
}
+ flags |= QIODevice::ReadWrite;
if (QFile::open(flags)) {
d->fileName = d->fileEngine->fileName(QAbstractFileEngine::DefaultName);
return true;
diff --git a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
index c6a43ff..26f5f40 100644
--- a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -87,6 +87,8 @@ private slots:
void stressTest();
void rename();
void renameFdLeak();
+ void reOpenThroughQFile();
+
public:
};
@@ -424,5 +426,18 @@ void tst_QTemporaryFile::renameFdLeak()
#endif
}
+void tst_QTemporaryFile::reOpenThroughQFile()
+{
+ QByteArray data("abcdefghij");
+
+ QTemporaryFile file;
+ QVERIFY(((QFile &)file).open(QIODevice::WriteOnly));
+ QCOMPARE(file.write(data), (qint64)data.size());
+
+ file.close();
+ QVERIFY(file.open());
+ QCOMPARE(file.readAll(), data);
+}
+
QTEST_MAIN(tst_QTemporaryFile)
#include "tst_qtemporaryfile.moc"