summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfile.cpp
diff options
context:
space:
mode:
authorJoão Abecasis <joao@trolltech.com>2010-01-13 17:09:18 (GMT)
committerJoão Abecasis <joao@trolltech.com>2010-01-18 14:17:26 (GMT)
commit54069f7c2c235dc9e302f96a6111bf6cd34a766b (patch)
treea11c31d17fdd64120a495697151450216382da7e /src/corelib/io/qfile.cpp
parentc7b3f408f772d565666910cb4495a7057796b648 (diff)
downloadQt-54069f7c2c235dc9e302f96a6111bf6cd34a766b.zip
Qt-54069f7c2c235dc9e302f96a6111bf6cd34a766b.tar.gz
Qt-54069f7c2c235dc9e302f96a6111bf6cd34a766b.tar.bz2
If the file is open, there must be an engine.
Don't try to allocate one for QFile::handle and QFile::flush since they'll be useless there. Reviewed-by: Markus Goetz
Diffstat (limited to 'src/corelib/io/qfile.cpp')
-rw-r--r--src/corelib/io/qfile.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp
index 7405339..df470b9 100644
--- a/src/corelib/io/qfile.cpp
+++ b/src/corelib/io/qfile.cpp
@@ -1152,12 +1152,11 @@ bool QFile::open(int fd, OpenMode mode)
int
QFile::handle() const
{
- if (!isOpen())
+ Q_D(const QFile);
+ if (!isOpen() || !d->fileEngine)
return -1;
- if (fileEngine())
- return d->fileEngine->handle();
- return -1;
+ return d->fileEngine->handle();
}
/*!
@@ -1353,7 +1352,11 @@ bool
QFile::flush()
{
Q_D(QFile);
- fileEngine();
+ if (!d->fileEngine) {
+ qWarning("QFile::flush: No file engine. Is IODevice open?");
+ return false;
+ }
+
if (!d->writeBuffer.isEmpty()) {
qint64 size = d->writeBuffer.size();
if (_qfile_writeData(d->fileEngine, &d->writeBuffer) != size) {
@@ -1394,7 +1397,7 @@ QFile::close()
d->writeBuffer.clear();
// keep earlier error from flush
- if (fileEngine()->close() && flushed)
+ if (d->fileEngine->close() && flushed)
unsetError();
else if (flushed)
d->setError(d->fileEngine->error(), d->fileEngine->errorString());