qfile.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qfile.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtCore module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qplatformdefs.h"-
41#include "qdebug.h"-
42#include "qfile.h"-
43#include "qfsfileengine_p.h"-
44#include "qtemporaryfile.h"-
45#include "qlist.h"-
46#include "qfileinfo.h"-
47#include "private/qiodevice_p.h"-
48#include "private/qfile_p.h"-
49#include "private/qfilesystemengine_p.h"-
50#include "private/qsystemerror_p.h"-
51#if defined(QT_BUILD_CORE_LIB)-
52# include "qcoreapplication.h"-
53#endif-
54-
55#ifdef QT_NO_QOBJECT-
56#define tr(X) QString::fromLatin1(X)-
57#endif-
58-
59QT_BEGIN_NAMESPACE-
60-
61//************* QFilePrivate-
62QFilePrivate::QFilePrivate()-
63{-
64}-
65-
66QFilePrivate::~QFilePrivate()-
67{-
68}-
69-
70bool-
71QFilePrivate::openExternalFile(int flags, int fd, QFile::FileHandleFlags handleFlags)-
72{-
73#ifdef QT_NO_FSFILEENGINE-
74 Q_UNUSED(flags);-
75 Q_UNUSED(fd);-
76 return false;-
77#else-
78 delete fileEngine;-
79 fileEngine = 0;-
80 QFSFileEngine *fe = new QFSFileEngine;-
81 fileEngine = fe;-
82 return fe->open(QIODevice::OpenMode(flags), fd, handleFlags);
executed 29 times by 3 tests: return fe->open(QIODevice::OpenMode(flags), fd, handleFlags);
Executed by:
  • tst_LargeFile
  • tst_QFile
  • tst_QPrinterInfo
29
83#endif-
84}-
85-
86bool-
87QFilePrivate::openExternalFile(int flags, FILE *fh, QFile::FileHandleFlags handleFlags)-
88{-
89#ifdef QT_NO_FSFILEENGINE-
90 Q_UNUSED(flags);-
91 Q_UNUSED(fh);-
92 return false;-
93#else-
94 delete fileEngine;-
95 fileEngine = 0;-
96 QFSFileEngine *fe = new QFSFileEngine;-
97 fileEngine = fe;-
98 return fe->open(QIODevice::OpenMode(flags), fh, handleFlags);
executed 364 times by 5 tests: return fe->open(QIODevice::OpenMode(flags), fh, handleFlags);
Executed by:
  • tst_LargeFile
  • tst_QFile
  • tst_qdbuscpp2xml - unknown status
  • tst_qdbusxml2cpp - unknown status
  • tst_qnetworkreply - unknown status
364
99#endif-
100}-
101-
102QAbstractFileEngine *QFilePrivate::engine() const-
103{-
104 if (!fileEngine)
!fileEngineDescription
TRUEevaluated 61986 times by 211 tests
Evaluated by:
  • tst_LargeFile
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QCryptographicHash
  • tst_QCssParser
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • ...
FALSEevaluated 260564 times by 167 tests
Evaluated by:
  • tst_LargeFile
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCryptographicHash
  • tst_QCssParser
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDialog
  • ...
61986-260564
105 fileEngine = QAbstractFileEngine::create(fileName);
executed 61986 times by 211 tests: fileEngine = QAbstractFileEngine::create(fileName);
Executed by:
  • tst_LargeFile
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QCryptographicHash
  • tst_QCssParser
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • ...
61986
106 return fileEngine;
executed 322550 times by 211 tests: return fileEngine;
Executed by:
  • tst_LargeFile
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QCryptographicHash
  • tst_QCssParser
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • ...
322550
107}-
108-
109//************* QFile-
110-
111/*!-
112 \class QFile-
113 \inmodule QtCore-
114 \brief The QFile class provides an interface for reading from and writing to files.-
115-
116 \ingroup io-
117-
118 \reentrant-
119-
120 QFile is an I/O device for reading and writing text and binary-
121 files and \l{The Qt Resource System}{resources}. A QFile may be-
122 used by itself or, more conveniently, with a QTextStream or-
123 QDataStream.-
124-
125 The file name is usually passed in the constructor, but it can be-
126 set at any time using setFileName(). QFile expects the file-
127 separator to be '/' regardless of operating system. The use of-
128 other separators (e.g., '\\') is not supported.-
129-
130 You can check for a file's existence using exists(), and remove a-
131 file using remove(). (More advanced file system related operations-
132 are provided by QFileInfo and QDir.)-
133-
134 The file is opened with open(), closed with close(), and flushed-
135 with flush(). Data is usually read and written using QDataStream-
136 or QTextStream, but you can also call the QIODevice-inherited-
137 functions read(), readLine(), readAll(), write(). QFile also-
138 inherits getChar(), putChar(), and ungetChar(), which work one-
139 character at a time.-
140-
141 The size of the file is returned by size(). You can get the-
142 current file position using pos(), or move to a new file position-
143 using seek(). If you've reached the end of the file, atEnd()-
144 returns \c true.-
145-
146 \section1 Reading Files Directly-
147-
148 The following example reads a text file line by line:-
149-
150 \snippet file/file.cpp 0-
151-
152 The QIODevice::Text flag passed to open() tells Qt to convert-
153 Windows-style line terminators ("\\r\\n") into C++-style-
154 terminators ("\\n"). By default, QFile assumes binary, i.e. it-
155 doesn't perform any conversion on the bytes stored in the file.-
156-
157 \section1 Using Streams to Read Files-
158-
159 The next example uses QTextStream to read a text file-
160 line by line:-
161-
162 \snippet file/file.cpp 1-
163-
164 QTextStream takes care of converting the 8-bit data stored on-
165 disk into a 16-bit Unicode QString. By default, it assumes that-
166 the user system's local 8-bit encoding is used (e.g., UTF-8-
167 on most unix based operating systems; see QTextCodec::codecForLocale() for-
168 details). This can be changed using \l QTextStream::setCodec().-
169-
170 To write text, we can use operator<<(), which is overloaded to-
171 take a QTextStream on the left and various data types (including-
172 QString) on the right:-
173-
174 \snippet file/file.cpp 2-
175-
176 QDataStream is similar, in that you can use operator<<() to write-
177 data and operator>>() to read it back. See the class-
178 documentation for details.-
179-
180 When you use QFile, QFileInfo, and QDir to access the file system-
181 with Qt, you can use Unicode file names. On Unix, these file-
182 names are converted to an 8-bit encoding. If you want to use-
183 standard C++ APIs (\c <cstdio> or \c <iostream>) or-
184 platform-specific APIs to access files instead of QFile, you can-
185 use the encodeName() and decodeName() functions to convert-
186 between Unicode file names and 8-bit file names.-
187-
188 On Unix, there are some special system files (e.g. in \c /proc) for which-
189 size() will always return 0, yet you may still be able to read more data-
190 from such a file; the data is generated in direct response to you calling-
191 read(). In this case, however, you cannot use atEnd() to determine if-
192 there is more data to read (since atEnd() will return true for a file that-
193 claims to have size 0). Instead, you should either call readAll(), or call-
194 read() or readLine() repeatedly until no more data can be read. The next-
195 example uses QTextStream to read \c /proc/modules line by line:-
196-
197 \snippet file/file.cpp 3-
198-
199 \section1 Signals-
200-
201 Unlike other QIODevice implementations, such as QTcpSocket, QFile does not-
202 emit the aboutToClose(), bytesWritten(), or readyRead() signals. This-
203 implementation detail means that QFile is not suitable for reading and-
204 writing certain types of files, such as device files on Unix platforms.-
205-
206 \section1 Platform Specific Issues-
207-
208 File permissions are handled differently on Unix-like systems and-
209 Windows. In a non \l{QIODevice::isWritable()}{writable}-
210 directory on Unix-like systems, files cannot be created. This is not always-
211 the case on Windows, where, for instance, the 'My Documents'-
212 directory usually is not writable, but it is still possible to-
213 create files in it.-
214-
215 Qt's understanding of file permissions is limited, which affects especially-
216 the \l QFile::setPermissions() function. On Windows, Qt will set only the-
217 legacy read-only flag, and that only when none of the Write* flags are-
218 passed. Qt does not manipulate access control lists (ACLs), which makes this-
219 function mostly useless for NTFS volumes. It may still be of use for USB-
220 sticks that use VFAT file systems. POSIX ACLs are not manipulated, either.-
221-
222 \sa QTextStream, QDataStream, QFileInfo, QDir, {The Qt Resource System}-
223*/-
224-
225#ifdef QT_NO_QOBJECT-
226QFile::QFile()-
227 : QFileDevice(*new QFilePrivate)-
228{-
229}-
230QFile::QFile(const QString &name)-
231 : QFileDevice(*new QFilePrivate)-
232{-
233 d_func()->fileName = name;-
234}-
235QFile::QFile(QFilePrivate &dd)-
236 : QFileDevice(dd)-
237{-
238}-
239#else-
240/*!-
241 Constructs a QFile object.-
242*/-
243QFile::QFile()-
244 : QFileDevice(*new QFilePrivate, 0)-
245{-
246}
executed 889 times by 47 tests: end of block
Executed by:
  • tst_LargeFile
  • tst_QAbstractItemView
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QErrorMessage
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QIODevice
  • tst_QIcon
  • tst_QImageIOHandler
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLabel
  • tst_QLineEdit
  • tst_QMessageBox
  • tst_QMetaType
  • ...
889
247/*!-
248 Constructs a new file object with the given \a parent.-
249*/-
250QFile::QFile(QObject *parent)-
251 : QFileDevice(*new QFilePrivate, parent)-
252{-
253}
executed 8 times by 2 tests: end of block
Executed by:
  • tst_QFile
  • tst_QVariant
8
254/*!-
255 Constructs a new file object to represent the file with the given \a name.-
256*/-
257QFile::QFile(const QString &name)-
258 : QFileDevice(*new QFilePrivate, 0)-
259{-
260 Q_D(QFile);-
261 d->fileName = name;-
262}
executed 62066 times by 211 tests: end of block
Executed by:
  • tst_LargeFile
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QCryptographicHash
  • tst_QCssParser
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • ...
62066
263/*!-
264 Constructs a new file object with the given \a parent to represent the-
265 file with the specified \a name.-
266*/-
267QFile::QFile(const QString &name, QObject *parent)-
268 : QFileDevice(*new QFilePrivate, parent)-
269{-
270 Q_D(QFile);-
271 d->fileName = name;-
272}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QFile
1
273/*!-
274 \internal-
275*/-
276QFile::QFile(QFilePrivate &dd, QObject *parent)-
277 : QFileDevice(dd, parent)-
278{-
279}
executed 1581 times by 25 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QColorDialog
  • tst_QDir
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QIcon
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLockFile
  • tst_QMetaType
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QPdfWriter
  • tst_QPixmap
  • tst_QSettings
  • tst_QStorageInfo
  • tst_QTemporaryFile
  • tst_languageChange
  • tst_qlockfile - unknown status
1581
280#endif-
281-
282/*!-
283 Destroys the file object, closing it if necessary.-
284*/-
285QFile::~QFile()-
286{-
287}-
288-
289/*!-
290 Returns the name set by setFileName() or to the QFile-
291 constructors.-
292-
293 \sa setFileName(), QFileInfo::fileName()-
294*/-
295QString QFile::fileName() const-
296{-
297 Q_D(const QFile);-
298 return d->engine()->fileName(QAbstractFileEngine::DefaultName);
executed 26052 times by 90 tests: return d->engine()->fileName(QAbstractFileEngine::DefaultName);
Executed by:
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDialog
  • tst_QDir
  • tst_QDoubleSpinBox
  • tst_QErrorMessage
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • ...
26052
299}-
300-
301/*!-
302 Sets the \a name of the file. The name can have no path, a-
303 relative path, or an absolute path.-
304-
305 Do not call this function if the file has already been opened.-
306-
307 If the file name has no path or a relative path, the path used-
308 will be the application's current directory path-
309 \e{at the time of the open()} call.-
310-
311 Example:-
312 \snippet code/src_corelib_io_qfile.cpp 0-
313-
314 Note that the directory separator "/" works for all operating-
315 systems supported by Qt.-
316-
317 \sa fileName(), QFileInfo, QDir-
318*/-
319void-
320QFile::setFileName(const QString &name)-
321{-
322 Q_D(QFile);-
323 if (isOpen()) {
isOpen()Description
TRUEnever evaluated
FALSEevaluated 3075 times by 43 tests
Evaluated by:
  • tst_LargeFile
  • tst_QAbstractItemView
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QErrorMessage
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsWidget
  • tst_QIODevice
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QLabel
  • tst_QLineEdit
  • tst_QMessageBox
  • tst_QNetworkReply
  • ...
0-3075
324 qWarning("QFile::setFileName: File (%s) is already opened",-
325 qPrintable(fileName()));-
326 close();-
327 }
never executed: end of block
0
328 if(d->fileEngine) { //get a new file engine later
d->fileEngineDescription
TRUEevaluated 2445 times by 16 tests
Evaluated by:
  • tst_LargeFile
  • tst_QDateTime
  • tst_QFile
  • tst_QGraphicsWidget
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QLabel
  • tst_QPixmap
  • tst_QRawFont
  • tst_QSharedPointer
  • tst_QSystemTrayIcon
  • tst_QTextBrowser
  • tst_QTextEdit
  • tst_QTimeZone
  • tst_QXmlSimpleReader
FALSEevaluated 630 times by 35 tests
Evaluated by:
  • tst_LargeFile
  • tst_QAbstractItemView
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QErrorMessage
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QIODevice
  • tst_QIcon
  • tst_QLabel
  • tst_QLineEdit
  • tst_QMessageBox
  • tst_QNetworkReply
  • tst_QPlainTextEdit
  • tst_QPrinter
  • tst_QSidebar
  • ...
630-2445
329 delete d->fileEngine;-
330 d->fileEngine = 0;-
331 }
executed 2445 times by 16 tests: end of block
Executed by:
  • tst_LargeFile
  • tst_QDateTime
  • tst_QFile
  • tst_QGraphicsWidget
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QLabel
  • tst_QPixmap
  • tst_QRawFont
  • tst_QSharedPointer
  • tst_QSystemTrayIcon
  • tst_QTextBrowser
  • tst_QTextEdit
  • tst_QTimeZone
  • tst_QXmlSimpleReader
2445
332 d->fileName = name;-
333}
executed 3075 times by 43 tests: end of block
Executed by:
  • tst_LargeFile
  • tst_QAbstractItemView
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTime
  • tst_QDateTimeEdit
  • tst_QErrorMessage
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsWidget
  • tst_QIODevice
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QLabel
  • tst_QLineEdit
  • tst_QMessageBox
  • tst_QNetworkReply
  • ...
3075
334-
335/*!-
336 \fn QString QFile::decodeName(const char *localFileName)-
337-
338 \overload-
339-
340 Returns the Unicode version of the given \a localFileName. See-
341 encodeName() for details.-
342*/-
343-
344/*!-
345 \fn QByteArray QFile::encodeName(const QString &fileName)-
346-
347 Converts \a fileName to the local 8-bit-
348 encoding determined by the user's locale. This is sufficient for-
349 file names that the user chooses. File names hard-coded into the-
350 application should only use 7-bit ASCII filename characters.-
351-
352 \sa decodeName()-
353*/-
354-
355/*!-
356 \typedef QFile::EncoderFn-
357 \obsolete-
358-
359 This is a typedef for a pointer to a function with the following-
360 signature:-
361-
362 \snippet code/src_corelib_io_qfile.cpp 1-
363-
364 \sa setEncodingFunction(), encodeName()-
365*/-
366-
367/*!-
368 \fn QString QFile::decodeName(const QByteArray &localFileName)-
369-
370 This does the reverse of QFile::encodeName() using \a localFileName.-
371-
372 \sa encodeName()-
373*/-
374-
375/*!-
376 \fn void QFile::setEncodingFunction(EncoderFn function)-
377 \obsolete-
378-
379 This function does nothing. It is provided for compatibility with Qt 4 code-
380 that attempted to set a different encoding function for file names. That-
381 feature is flawed and no longer supported in Qt 5.-
382-
383 \sa encodeName(), setDecodingFunction()-
384*/-
385-
386/*!-
387 \typedef QFile::DecoderFn-
388-
389 This is a typedef for a pointer to a function with the following-
390 signature:-
391-
392 \snippet code/src_corelib_io_qfile.cpp 2-
393-
394 \sa setDecodingFunction()-
395*/-
396-
397/*!-
398 \fn void QFile::setDecodingFunction(DecoderFn function)-
399 \obsolete-
400-
401 This function does nothing. It is provided for compatibility with Qt 4 code-
402 that attempted to set a different decoding function for file names. That-
403 feature is flawed and no longer supported in Qt 5.-
404-
405 \sa setEncodingFunction(), decodeName()-
406*/-
407-
408/*!-
409 \overload-
410-
411 Returns \c true if the file specified by fileName() exists; otherwise-
412 returns \c false.-
413-
414 \sa fileName(), setFileName()-
415*/-
416-
417bool-
418QFile::exists() const-
419{-
420 Q_D(const QFile);-
421 // 0x1000000 = QAbstractFileEngine::Refresh, forcing an update-
422 return (d->engine()->fileFlags(QAbstractFileEngine::FlagsMask
executed 2484 times by 57 tests: return (d->engine()->fileFlags(QAbstractFileEngine::FlagsMask | QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);
Executed by:
  • tst_LargeFile
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDateTimeEdit
  • tst_QDir
  • tst_QDirModel
  • tst_QErrorMessage
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • ...
2484
423 | QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);
executed 2484 times by 57 tests: return (d->engine()->fileFlags(QAbstractFileEngine::FlagsMask | QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);
Executed by:
  • tst_LargeFile
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAccessibility
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDateTimeEdit
  • tst_QDir
  • tst_QDirModel
  • tst_QErrorMessage
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QGraphicsProxyWidget
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • ...
2484
424}-
425-
426/*!-
427 Returns \c true if the file specified by \a fileName exists; otherwise-
428 returns \c false.-
429-
430 \note If \a fileName is a symlink that points to a non-existing-
431 file, false is returned.-
432*/-
433-
434bool-
435QFile::exists(const QString &fileName)-
436{-
437 return QFileInfo::exists(fileName);
executed 12500 times by 218 tests: return QFileInfo::exists(fileName);
Executed by:
  • tst_Gestures
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAbstractSpinBox
  • tst_QAccessibility
  • tst_QAction
  • tst_QApplication
  • tst_QBackingStore
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QClipboard
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QCryptographicHash
  • ...
12500
438}-
439-
440/*!-
441 \fn QString QFile::symLinkTarget() const-
442 \since 4.2-
443 \overload-
444-
445 Returns the absolute path of the file or directory a symlink (or shortcut-
446 on Windows) points to, or a an empty string if the object isn't a symbolic-
447 link.-
448-
449 This name may not represent an existing file; it is only a string.-
450 QFile::exists() returns \c true if the symlink points to an existing file.-
451-
452 \sa fileName(), setFileName()-
453*/-
454-
455/*!-
456 \obsolete-
457-
458 Use symLinkTarget() instead.-
459*/-
460QString-
461QFile::readLink() const-
462{-
463 Q_D(const QFile);-
464 return d->engine()->fileName(QAbstractFileEngine::LinkName);
executed 2 times by 1 test: return d->engine()->fileName(QAbstractFileEngine::LinkName);
Executed by:
  • tst_QFile
2
465}-
466-
467/*!-
468 \fn static QString QFile::symLinkTarget(const QString &fileName)-
469 \since 4.2-
470-
471 Returns the absolute path of the file or directory referred to by the-
472 symlink (or shortcut on Windows) specified by \a fileName, or returns an-
473 empty string if the \a fileName does not correspond to a symbolic link.-
474-
475 This name may not represent an existing file; it is only a string.-
476 QFile::exists() returns \c true if the symlink points to an existing file.-
477*/-
478-
479/*!-
480 \obsolete-
481-
482 Use symLinkTarget() instead.-
483*/-
484QString-
485QFile::readLink(const QString &fileName)-
486{-
487 return QFileInfo(fileName).readLink();
executed 1 time by 1 test: return QFileInfo(fileName).readLink();
Executed by:
  • tst_QFile
1
488}-
489-
490/*!-
491 Removes the file specified by fileName(). Returns \c true if successful;-
492 otherwise returns \c false.-
493-
494 The file is closed before it is removed.-
495-
496 \sa setFileName()-
497*/-
498-
499bool-
500QFile::remove()-
501{-
502 Q_D(QFile);-
503 if (d->fileName.isEmpty()) {
d->fileName.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 13262 times by 76 tests
Evaluated by:
  • tst_LargeFile
  • tst_QAbstractFileEngine
  • tst_QAbstractNetworkCache
  • tst_QColorDialog
  • tst_QDataStream
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QIODevice
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QLockFile
  • tst_QLoggingRegistry
  • tst_QMimeDatabase
  • ...
0-13262
504 qWarning("QFile::remove: Empty or null file name");-
505 return false;
never executed: return false;
0
506 }-
507 unsetError();-
508 close();-
509 if(error() == QFile::NoError) {
error() == QFile::NoErrorDescription
TRUEevaluated 13262 times by 76 tests
Evaluated by:
  • tst_LargeFile
  • tst_QAbstractFileEngine
  • tst_QAbstractNetworkCache
  • tst_QColorDialog
  • tst_QDataStream
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QIODevice
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QLockFile
  • tst_QLoggingRegistry
  • tst_QMimeDatabase
  • ...
FALSEnever evaluated
0-13262
510 if (d->engine()->remove()) {
d->engine()->remove()Description
TRUEevaluated 12666 times by 76 tests
Evaluated by:
  • tst_LargeFile
  • tst_QAbstractFileEngine
  • tst_QAbstractNetworkCache
  • tst_QColorDialog
  • tst_QDataStream
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QIODevice
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QLockFile
  • tst_QLoggingRegistry
  • tst_QMimeDatabase
  • ...
FALSEevaluated 596 times by 21 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemWatcher
  • tst_QIODevice
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QPrinter
  • tst_QSaveFile
  • tst_QSettings
  • tst_QSharedMemory
  • tst_QTextStream
  • tst_QXmlStream
  • tst_qmake
  • tst_qstandardpaths
  • tst_selftests - unknown status
596-12666
511 unsetError();-
512 return true;
executed 12666 times by 76 tests: return true;
Executed by:
  • tst_LargeFile
  • tst_QAbstractFileEngine
  • tst_QAbstractNetworkCache
  • tst_QColorDialog
  • tst_QDataStream
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QIODevice
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QLockFile
  • tst_QLoggingRegistry
  • tst_QMimeDatabase
  • ...
12666
513 }-
514 d->setError(QFile::RemoveError, d->fileEngine->errorString());-
515 }
executed 596 times by 21 tests: end of block
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemWatcher
  • tst_QIODevice
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QPrinter
  • tst_QSaveFile
  • tst_QSettings
  • tst_QSharedMemory
  • tst_QTextStream
  • tst_QXmlStream
  • tst_qmake
  • tst_qstandardpaths
  • tst_selftests - unknown status
596
516 return false;
executed 596 times by 21 tests: return false;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemWatcher
  • tst_QIODevice
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QPrinter
  • tst_QSaveFile
  • tst_QSettings
  • tst_QSharedMemory
  • tst_QTextStream
  • tst_QXmlStream
  • tst_qmake
  • tst_qstandardpaths
  • tst_selftests - unknown status
596
517}-
518-
519/*!-
520 \overload-
521-
522 Removes the file specified by the \a fileName given.-
523-
524 Returns \c true if successful; otherwise returns \c false.-
525-
526 \sa remove()-
527*/-
528-
529bool-
530QFile::remove(const QString &fileName)-
531{-
532 return QFile(fileName).remove();
executed 11763 times by 68 tests: return QFile(fileName).remove();
Executed by:
  • tst_QAbstractFileEngine
  • tst_QAbstractNetworkCache
  • tst_QColorDialog
  • tst_QDataStream
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QFiledialog
  • tst_QFtp
  • tst_QGraphicsProxyWidget
  • tst_QIODevice
  • tst_QIcon
  • tst_QImage
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QLockFile
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QNetworkSession
  • ...
11763
533}-
534-
535/*!-
536 Renames the file currently specified by fileName() to \a newName.-
537 Returns \c true if successful; otherwise returns \c false.-
538-
539 If a file with the name \a newName already exists, rename() returns \c false-
540 (i.e., QFile will not overwrite it).-
541-
542 The file is closed before it is renamed.-
543-
544 If the rename operation fails, Qt will attempt to copy this file's-
545 contents to \a newName, and then remove this file, keeping only-
546 \a newName. If that copy operation fails or this file can't be removed,-
547 the destination file \a newName is removed to restore the old state.-
548-
549 \sa setFileName()-
550*/-
551-
552bool-
553QFile::rename(const QString &newName)-
554{-
555 Q_D(QFile);-
556 if (d->fileName.isEmpty()) {
d->fileName.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 259 times by 14 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QSettings
  • tst_QTemporaryDir
  • tst_QTemporaryFile
0-259
557 qWarning("QFile::rename: Empty or null file name");-
558 return false;
never executed: return false;
0
559 }-
560 if (d->fileName == newName) {
d->fileName == newNameDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFile
FALSEevaluated 258 times by 14 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QSettings
  • tst_QTemporaryDir
  • tst_QTemporaryFile
1-258
561 d->setError(QFile::RenameError, tr("Destination file is the same file."));-
562 return false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QFile
1
563 }-
564 if (!exists()) {
!exists()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QFile
FALSEevaluated 256 times by 14 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QSettings
  • tst_QTemporaryDir
  • tst_QTemporaryFile
2-256
565 d->setError(QFile::RenameError, tr("Source file does not exist."));-
566 return false;
executed 2 times by 1 test: return false;
Executed by:
  • tst_QFile
2
567 }-
568 // If the file exists and it is a case-changing rename ("foo" -> "Foo"),-
569 // compare Ids to make sure it really is a different file.-
570 if (QFile::exists(newName)) {
QFile::exists(newName)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFile
FALSEevaluated 252 times by 14 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QSettings
  • tst_QTemporaryDir
  • tst_QTemporaryFile
4-252
571 if (d->fileName.compare(newName, Qt::CaseInsensitive)
d->fileName.co...seInsensitive)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QFile
FALSEnever evaluated
0-4
572 || QFileSystemEngine::id(QFileSystemEntry(d->fileName)) != QFileSystemEngine::id(QFileSystemEntry(newName))) {
QFileSystemEng...ntry(newName))Description
TRUEnever evaluated
FALSEnever evaluated
0
573 // ### Race condition. If a file is moved in after this, it /will/ be-
574 // overwritten. On Unix, the proper solution is to use hardlinks:-
575 // return ::link(old, new) && ::remove(old);-
576 d->setError(QFile::RenameError, tr("Destination file exists"));-
577 return false;
executed 4 times by 1 test: return false;
Executed by:
  • tst_QFile
4
578 }-
579#ifndef QT_NO_TEMPORARYFILE-
580 // This #ifndef disables the workaround it encloses. Therefore, this configuration is not recommended.-
581#ifdef Q_OS_LINUX-
582 // rename() on Linux simply does nothing when renaming "foo" to "Foo" on a case-insensitive-
583 // FS, such as FAT32. Move the file away and rename in 2 steps to work around.-
584 QTemporaryFile tempFile(d->fileName + QLatin1String(".XXXXXX"));-
585 tempFile.setAutoRemove(false);-
586 if (!tempFile.open(QIODevice::ReadWrite)) {
!tempFile.open...ce::ReadWrite)Description
TRUEnever evaluated
FALSEnever evaluated
0
587 d->setError(QFile::RenameError, tempFile.errorString());-
588 return false;
never executed: return false;
0
589 }-
590 tempFile.close();-
591 if (!d->engine()->rename(tempFile.fileName())) {
!d->engine()->...le.fileName())Description
TRUEnever evaluated
FALSEnever evaluated
0
592 d->setError(QFile::RenameError, tr("Error while renaming."));-
593 return false;
never executed: return false;
0
594 }-
595 if (tempFile.rename(newName)) {
tempFile.rename(newName)Description
TRUEnever evaluated
FALSEnever evaluated
0
596 d->fileEngine->setFileName(newName);-
597 d->fileName = newName;-
598 return true;
never executed: return true;
0
599 }-
600 d->setError(QFile::RenameError, tempFile.errorString());-
601 // We need to restore the original file.-
602 if (!tempFile.rename(d->fileName)) {
!tempFile.rename(d->fileName)Description
TRUEnever evaluated
FALSEnever evaluated
0
603 d->setError(QFile::RenameError, errorString() + QLatin1Char('\n')-
604 + tr("Unable to restore from %1: %2").-
605 arg(QDir::toNativeSeparators(tempFile.fileName()), tempFile.errorString()));-
606 }
never executed: end of block
0
607 return false;
never executed: return false;
0
608#endif // Q_OS_LINUX-
609#endif // QT_NO_TEMPORARYFILE-
610 }-
611 unsetError();-
612 close();-
613 if(error() == QFile::NoError) {
error() == QFile::NoErrorDescription
TRUEevaluated 252 times by 14 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QSettings
  • tst_QTemporaryDir
  • tst_QTemporaryFile
FALSEnever evaluated
0-252
614 if (d->engine()->rename(newName)) {
d->engine()->rename(newName)Description
TRUEevaluated 248 times by 14 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QSettings
  • tst_QTemporaryDir
  • tst_QTemporaryFile
FALSEevaluated 4 times by 3 tests
Evaluated by:
  • tst_QDir
  • tst_QFile
  • tst_QTemporaryFile
4-248
615 unsetError();-
616 // engine was able to handle the new name so we just reset it-
617 d->fileEngine->setFileName(newName);-
618 d->fileName = newName;-
619 return true;
executed 248 times by 14 tests: return true;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QDir
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QSettings
  • tst_QTemporaryDir
  • tst_QTemporaryFile
248
620 }-
621-
622 if (isSequential()) {
isSequential()Description
TRUEnever evaluated
FALSEevaluated 4 times by 3 tests
Evaluated by:
  • tst_QDir
  • tst_QFile
  • tst_QTemporaryFile
0-4
623 d->setError(QFile::RenameError, tr("Will not rename sequential file using block copy"));-
624 return false;
never executed: return false;
0
625 }-
626-
627 QFile out(newName);-
628 if (open(QIODevice::ReadOnly)) {
open(QIODevice::ReadOnly)Description
TRUEevaluated 4 times by 3 tests
Evaluated by:
  • tst_QDir
  • tst_QFile
  • tst_QTemporaryFile
FALSEnever evaluated
0-4
629 if (out.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
out.open(QIODe...ice::Truncate)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFile
FALSEevaluated 3 times by 3 tests
Evaluated by:
  • tst_QDir
  • tst_QFile
  • tst_QTemporaryFile
1-3
630 bool error = false;-
631 char block[4096];-
632 qint64 bytes;-
633 while ((bytes = read(block, sizeof(block))) > 0) {
(bytes = read(...f(block))) > 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFile
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFile
1
634 if (bytes != out.write(block, bytes)) {
bytes != out.w...(block, bytes)Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFile
0-1
635 d->setError(QFile::RenameError, out.errorString());-
636 error = true;-
637 break;
never executed: break;
0
638 }-
639 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QFile
1
640 if (bytes == -1) {
bytes == -1Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFile
0-1
641 d->setError(QFile::RenameError, errorString());-
642 error = true;-
643 }
never executed: end of block
0
644 if(!error) {
!errorDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFile
FALSEnever evaluated
0-1
645 if (!remove()) {
!remove()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFile
FALSEnever evaluated
0-1
646 d->setError(QFile::RenameError, tr("Cannot remove source file"));-
647 error = true;-
648 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QFile
1
649 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QFile
1
650 if (error) {
errorDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFile
FALSEnever evaluated
0-1
651 out.remove();-
652 } else {
executed 1 time by 1 test: end of block
Executed by:
  • tst_QFile
1
653 d->fileEngine->setFileName(newName);-
654 setPermissions(permissions());-
655 unsetError();-
656 setFileName(newName);-
657 }
never executed: end of block
0
658 close();-
659 return !error;
executed 1 time by 1 test: return !error;
Executed by:
  • tst_QFile
1
660 }-
661 close();-
662 }
executed 3 times by 3 tests: end of block
Executed by:
  • tst_QDir
  • tst_QFile
  • tst_QTemporaryFile
3
663 d->setError(QFile::RenameError, out.isOpen() ? errorString() : out.errorString());-
664 }
executed 3 times by 3 tests: end of block
Executed by:
  • tst_QDir
  • tst_QFile
  • tst_QTemporaryFile
3
665 return false;
executed 3 times by 3 tests: return false;
Executed by:
  • tst_QDir
  • tst_QFile
  • tst_QTemporaryFile
3
666}-
667-
668/*!-
669 \overload-
670-
671 Renames the file \a oldName to \a newName. Returns \c true if-
672 successful; otherwise returns \c false.-
673-
674 If a file with the name \a newName already exists, rename() returns \c false-
675 (i.e., QFile will not overwrite it).-
676-
677 \sa rename()-
678*/-
679-
680bool-
681QFile::rename(const QString &oldName, const QString &newName)-
682{-
683 return QFile(oldName).rename(newName);
executed 8 times by 3 tests: return QFile(oldName).rename(newName);
Executed by:
  • tst_QFile
  • tst_QFileSystemModel
  • tst_QSettings
8
684}-
685-
686/*!-
687-
688 Creates a link named \a linkName that points to the file currently specified by-
689 fileName(). What a link is depends on the underlying filesystem (be it a-
690 shortcut on Windows or a symbolic link on Unix). Returns \c true if successful;-
691 otherwise returns \c false.-
692-
693 This function will not overwrite an already existing entity in the file system;-
694 in this case, \c link() will return false and set \l{QFile::}{error()} to-
695 return \l{QFile::}{RenameError}.-
696-
697 \note To create a valid link on Windows, \a linkName must have a \c{.lnk} file extension.-
698-
699 \sa setFileName()-
700*/-
701-
702bool-
703QFile::link(const QString &linkName)-
704{-
705 Q_D(QFile);-
706 if (d->fileName.isEmpty()) {
d->fileName.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 161 times by 8 tests
Evaluated by:
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QMimeDatabase
  • tst_QSaveFile
  • tst_qstandardpaths
0-161
707 qWarning("QFile::link: Empty or null file name");-
708 return false;
never executed: return false;
0
709 }-
710 QFileInfo fi(linkName);-
711 if (d->engine()->link(fi.absoluteFilePath())) {
d->engine()->l...uteFilePath())Description
TRUEevaluated 161 times by 8 tests
Evaluated by:
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QMimeDatabase
  • tst_QSaveFile
  • tst_qstandardpaths
FALSEnever evaluated
0-161
712 unsetError();-
713 return true;
executed 161 times by 8 tests: return true;
Executed by:
  • tst_QDir
  • tst_QDirIterator
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QMimeDatabase
  • tst_QSaveFile
  • tst_qstandardpaths
161
714 }-
715 d->setError(QFile::RenameError, d->fileEngine->errorString());-
716 return false;
never executed: return false;
0
717}-
718-
719/*!-
720 \overload-
721-
722 Creates a link named \a linkName that points to the file \a fileName. What a link is-
723 depends on the underlying filesystem (be it a shortcut on Windows-
724 or a symbolic link on Unix). Returns \c true if successful; otherwise-
725 returns \c false.-
726-
727 \sa link()-
728*/-
729-
730bool-
731QFile::link(const QString &fileName, const QString &linkName)-
732{-
733 return QFile(fileName).link(linkName);
executed 151 times by 5 tests: return QFile(fileName).link(linkName);
Executed by:
  • tst_QDir
  • tst_QDirIterator
  • tst_QFile
  • tst_QMimeDatabase
  • tst_QSaveFile
151
734}-
735-
736/*!-
737 Copies the file currently specified by fileName() to a file called-
738 \a newName. Returns \c true if successful; otherwise returns \c false.-
739-
740 Note that if a file with the name \a newName already exists,-
741 copy() returns \c false (i.e. QFile will not overwrite it).-
742-
743 The source file is closed before it is copied.-
744-
745 \sa setFileName()-
746*/-
747-
748bool-
749QFile::copy(const QString &newName)-
750{-
751 Q_D(QFile);-
752 if (d->fileName.isEmpty()) {
d->fileName.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 137 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
0-137
753 qWarning("QFile::copy: Empty or null file name");-
754 return false;
never executed: return false;
0
755 }-
756 if (QFile::exists(newName)) {
QFile::exists(newName)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QFile
FALSEevaluated 134 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
3-134
757 // ### Race condition. If a file is moved in after this, it /will/ be-
758 // overwritten. On Unix, the proper solution is to use hardlinks:-
759 // return ::link(old, new) && ::remove(old); See also rename().-
760 d->setError(QFile::CopyError, tr("Destination file exists"));-
761 return false;
executed 3 times by 1 test: return false;
Executed by:
  • tst_QFile
3
762 }-
763 unsetError();-
764 close();-
765 if(error() == QFile::NoError) {
error() == QFile::NoErrorDescription
TRUEevaluated 134 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
FALSEnever evaluated
0-134
766 if (d->engine()->copy(newName)) {
d->engine()->copy(newName)Description
TRUEnever evaluated
FALSEevaluated 134 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
0-134
767 unsetError();-
768 return true;
never executed: return true;
0
769 } else {-
770 bool error = false;-
771 if(!open(QFile::ReadOnly)) {
!open(QFile::ReadOnly)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFile
FALSEevaluated 133 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
1-133
772 error = true;-
773 d->setError(QFile::CopyError, tr("Cannot open %1 for input").arg(d->fileName));-
774 } else {
executed 1 time by 1 test: end of block
Executed by:
  • tst_QFile
1
775 QString fileTemplate = QLatin1String("%1/qt_temp.XXXXXX");-
776#ifdef QT_NO_TEMPORARYFILE-
777 QFile out(fileTemplate.arg(QFileInfo(newName).path()));-
778 if (!out.open(QIODevice::ReadWrite))-
779 error = true;-
780#else-
781 QTemporaryFile out(fileTemplate.arg(QFileInfo(newName).path()));-
782 if (!out.open()) {
!out.open()Description
TRUEnever evaluated
FALSEevaluated 133 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
0-133
783 out.setFileTemplate(fileTemplate.arg(QDir::tempPath()));-
784 if (!out.open())
!out.open()Description
TRUEnever evaluated
FALSEnever evaluated
0
785 error = true;
never executed: error = true;
0
786 }
never executed: end of block
0
787#endif-
788 if (error) {
errorDescription
TRUEnever evaluated
FALSEevaluated 133 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
0-133
789 out.close();-
790 close();-
791 d->setError(QFile::CopyError, tr("Cannot open for output"));-
792 } else {
never executed: end of block
0
793 char block[4096];-
794 qint64 totalRead = 0;-
795 while(!atEnd()) {
!atEnd()Description
TRUEevaluated 1271 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
FALSEevaluated 133 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
133-1271
796 qint64 in = read(block, sizeof(block));-
797 if (in <= 0)
in <= 0Description
TRUEnever evaluated
FALSEevaluated 1271 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
0-1271
798 break;
never executed: break;
0
799 totalRead += in;-
800 if(in != out.write(block, in)) {
in != out.write(block, in)Description
TRUEnever evaluated
FALSEevaluated 1271 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
0-1271
801 close();-
802 d->setError(QFile::CopyError, tr("Failure to write block"));-
803 error = true;-
804 break;
never executed: break;
0
805 }-
806 }
executed 1271 times by 5 tests: end of block
Executed by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
1271
807-
808 if (totalRead != size()) {
totalRead != size()Description
TRUEnever evaluated
FALSEevaluated 133 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
0-133
809 // Unable to read from the source. The error string is-
810 // already set from read().-
811 error = true;-
812 }
never executed: end of block
0
813 if (!error && !out.rename(newName)) {
!errorDescription
TRUEevaluated 133 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
FALSEnever evaluated
!out.rename(newName)Description
TRUEnever evaluated
FALSEevaluated 133 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
0-133
814 error = true;-
815 close();-
816 d->setError(QFile::CopyError, tr("Cannot create %1 for output").arg(newName));-
817 }
never executed: end of block
0
818#ifdef QT_NO_TEMPORARYFILE-
819 if (error)-
820 out.remove();-
821#else-
822 if (!error)
!errorDescription
TRUEevaluated 133 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
FALSEnever evaluated
0-133
823 out.setAutoRemove(false);
executed 133 times by 5 tests: out.setAutoRemove(false);
Executed by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
133
824#endif-
825 }
executed 133 times by 5 tests: end of block
Executed by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
133
826 }-
827 if(!error) {
!errorDescription
TRUEevaluated 133 times by 5 tests
Evaluated by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QFile
1-133
828 QFile::setPermissions(newName, permissions());-
829 close();-
830 unsetError();-
831 return true;
executed 133 times by 5 tests: return true;
Executed by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
133
832 }-
833 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QFile
1
834 }-
835 return false;
executed 1 time by 1 test: return false;
Executed by:
  • tst_QFile
1
836}-
837-
838/*!-
839 \overload-
840-
841 Copies the file \a fileName to \a newName. Returns \c true if successful;-
842 otherwise returns \c false.-
843-
844 If a file with the name \a newName already exists, copy() returns \c false-
845 (i.e., QFile will not overwrite it).-
846-
847 \sa rename()-
848*/-
849-
850bool-
851QFile::copy(const QString &fileName, const QString &newName)-
852{-
853 return QFile(fileName).copy(newName);
executed 101 times by 3 tests: return QFile(fileName).copy(newName);
Executed by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QImageReader
101
854}-
855-
856/*!-
857 Opens the file using OpenMode \a mode, returning true if successful;-
858 otherwise false.-
859-
860 The \a mode must be QIODevice::ReadOnly, QIODevice::WriteOnly, or-
861 QIODevice::ReadWrite. It may also have additional flags, such as-
862 QIODevice::Text and QIODevice::Unbuffered.-
863-
864 \note In \l{QIODevice::}{WriteOnly} or \l{QIODevice::}{ReadWrite}-
865 mode, if the relevant file does not already exist, this function-
866 will try to create a new file before opening it.-
867-
868 \sa QIODevice::OpenMode, setFileName()-
869*/-
870bool QFile::open(OpenMode mode)-
871{-
872 Q_D(QFile);-
873 if (isOpen()) {
isOpen()Description
TRUEnever evaluated
FALSEevaluated 48863 times by 193 tests
Evaluated by:
  • tst_LargeFile
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QCryptographicHash
  • tst_QCssParser
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • ...
0-48863
874 qWarning("QFile::open: File (%s) already open", qPrintable(fileName()));-
875 return false;
never executed: return false;
0
876 }-
877 if (mode & Append)
mode & AppendDescription
TRUEevaluated 259 times by 6 tests
Evaluated by:
  • tst_QAbstractFileEngine
  • tst_QFile
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_qfileopenevent
  • tst_qmakelib
FALSEevaluated 48604 times by 193 tests
Evaluated by:
  • tst_LargeFile
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QCryptographicHash
  • tst_QCssParser
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • ...
259-48604
878 mode |= WriteOnly;
executed 259 times by 6 tests: mode |= WriteOnly;
Executed by:
  • tst_QAbstractFileEngine
  • tst_QFile
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_qfileopenevent
  • tst_qmakelib
259
879-
880 unsetError();-
881 if ((mode & (ReadOnly | WriteOnly)) == 0) {
(mode & (ReadO...iteOnly)) == 0Description
TRUEnever evaluated
FALSEevaluated 48863 times by 193 tests
Evaluated by:
  • tst_LargeFile
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QCryptographicHash
  • tst_QCssParser
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • ...
0-48863
882 qWarning("QIODevice::open: File access not specified");-
883 return false;
never executed: return false;
0
884 }-
885-
886 // QIODevice provides the buffering, so there's no need to request it from the file engine.-
887 if (d->engine()->open(mode | QIODevice::Unbuffered)) {
d->engine()->o...e::Unbuffered)Description
TRUEevaluated 45153 times by 177 tests
Evaluated by:
  • tst_LargeFile
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCryptographicHash
  • tst_QCssParser
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDateTime
  • tst_QDateTimeEdit
  • ...
FALSEevaluated 3710 times by 53 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QApplication
  • tst_QCommandLineParser
  • tst_QCoreApplication
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • tst_QDBusConnection_Delayed
  • tst_QDateTime
  • tst_QDir
  • tst_QDnsLookup_Appless
  • tst_QFile
  • tst_QGlobal
  • tst_QGraphicsWidget
  • tst_QGuiApplication
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLabel
  • tst_QLoggingRegistry
  • tst_QMimeDatabase
  • tst_QNetworkConfigurationManager
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QPixmap
  • ...
3710-45153
888 QIODevice::open(mode);-
889 if (mode & Append)
mode & AppendDescription
TRUEevaluated 258 times by 6 tests
Evaluated by:
  • tst_QAbstractFileEngine
  • tst_QFile
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_qfileopenevent
  • tst_qmakelib
FALSEevaluated 44895 times by 177 tests
Evaluated by:
  • tst_LargeFile
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCryptographicHash
  • tst_QCssParser
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDateTime
  • tst_QDateTimeEdit
  • ...
258-44895
890 seek(size());
executed 258 times by 6 tests: seek(size());
Executed by:
  • tst_QAbstractFileEngine
  • tst_QFile
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_qfileopenevent
  • tst_qmakelib
258
891 return true;
executed 45153 times by 177 tests: return true;
Executed by:
  • tst_LargeFile
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCryptographicHash
  • tst_QCssParser
  • tst_QDBusMarshall
  • tst_QDataStream
  • tst_QDateTime
  • tst_QDateTimeEdit
  • ...
45153
892 }-
893 QFile::FileError err = d->fileEngine->error();-
894 if(err == QFile::UnspecifiedError)
err == QFile::UnspecifiedErrorDescription
TRUEevaluated 215 times by 8 tests
Evaluated by:
  • tst_QFile
  • tst_QImageReader
  • tst_QPlainTextEdit
  • tst_QSettings
  • tst_QTextBrowser
  • tst_QTextDocument
  • tst_QTextEdit
  • tst_Selftests
FALSEevaluated 3495 times by 50 tests
Evaluated by:
  • tst_QAbstractNetworkCache
  • tst_QApplication
  • tst_QCommandLineParser
  • tst_QCoreApplication
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • tst_QDBusConnection_Delayed
  • tst_QDateTime
  • tst_QDir
  • tst_QDnsLookup_Appless
  • tst_QFile
  • tst_QGlobal
  • tst_QGraphicsWidget
  • tst_QGuiApplication
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLabel
  • tst_QLoggingRegistry
  • tst_QMimeDatabase
  • tst_QNetworkConfigurationManager
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QPixmap
  • ...
215-3495
895 err = QFile::OpenError;
executed 215 times by 8 tests: err = QFile::OpenError;
Executed by:
  • tst_QFile
  • tst_QImageReader
  • tst_QPlainTextEdit
  • tst_QSettings
  • tst_QTextBrowser
  • tst_QTextDocument
  • tst_QTextEdit
  • tst_Selftests
215
896 d->setError(err, d->fileEngine->errorString());-
897 return false;
executed 3710 times by 53 tests: return false;
Executed by:
  • tst_QAbstractNetworkCache
  • tst_QApplication
  • tst_QCommandLineParser
  • tst_QCoreApplication
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • tst_QDBusConnection_Delayed
  • tst_QDateTime
  • tst_QDir
  • tst_QDnsLookup_Appless
  • tst_QFile
  • tst_QGlobal
  • tst_QGraphicsWidget
  • tst_QGuiApplication
  • tst_QIcon
  • tst_QImage
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLabel
  • tst_QLoggingRegistry
  • tst_QMimeDatabase
  • tst_QNetworkConfigurationManager
  • tst_QNetworkDiskCache
  • tst_QNetworkReply
  • tst_QPixmap
  • ...
3710
898}-
899-
900/*!-
901 \overload-
902-
903 Opens the existing file handle \a fh in the given \a mode.-
904 \a handleFlags may be used to specify additional options.-
905 Returns \c true if successful; otherwise returns \c false.-
906-
907 Example:-
908 \snippet code/src_corelib_io_qfile.cpp 3-
909-
910 When a QFile is opened using this function, behaviour of close() is-
911 controlled by the AutoCloseHandle flag.-
912 If AutoCloseHandle is specified, and this function succeeds,-
913 then calling close() closes the adopted handle.-
914 Otherwise, close() does not actually close the file, but only flushes it.-
915-
916 \b{Warning:}-
917 \list 1-
918 \li If \a fh does not refer to a regular file, e.g., it is \c stdin,-
919 \c stdout, or \c stderr, you may not be able to seek(). size()-
920 returns \c 0 in those cases. See QIODevice::isSequential() for-
921 more information.-
922 \li Since this function opens the file without specifying the file name,-
923 you cannot use this QFile with a QFileInfo.-
924 \endlist-
925-
926 \sa close()-
927-
928 \b{Note for the Windows Platform}-
929-
930 \a fh must be opened in binary mode (i.e., the mode string must contain-
931 'b', as in "rb" or "wb") when accessing files and other random-access-
932 devices. Qt will translate the end-of-line characters if you pass-
933 QIODevice::Text to \a mode. Sequential devices, such as stdin and stdout,-
934 are unaffected by this limitation.-
935-
936 You need to enable support for console applications in order to use the-
937 stdin, stdout and stderr streams at the console. To do this, add the-
938 following declaration to your application's project file:-
939-
940 \snippet code/src_corelib_io_qfile.cpp 4-
941*/-
942bool QFile::open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)-
943{-
944 Q_D(QFile);-
945 if (isOpen()) {
isOpen()Description
TRUEnever evaluated
FALSEevaluated 364 times by 5 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
  • tst_qdbuscpp2xml - unknown status
  • tst_qdbusxml2cpp - unknown status
  • tst_qnetworkreply - unknown status
0-364
946 qWarning("QFile::open: File (%s) already open", qPrintable(fileName()));-
947 return false;
never executed: return false;
0
948 }-
949 if (mode & Append)
mode & AppendDescription
TRUEnever evaluated
FALSEevaluated 364 times by 5 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
  • tst_qdbuscpp2xml - unknown status
  • tst_qdbusxml2cpp - unknown status
  • tst_qnetworkreply - unknown status
0-364
950 mode |= WriteOnly;
never executed: mode |= WriteOnly;
0
951 unsetError();-
952 if ((mode & (ReadOnly | WriteOnly)) == 0) {
(mode & (ReadO...iteOnly)) == 0Description
TRUEnever evaluated
FALSEevaluated 364 times by 5 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
  • tst_qdbuscpp2xml - unknown status
  • tst_qdbusxml2cpp - unknown status
  • tst_qnetworkreply - unknown status
0-364
953 qWarning("QFile::open: File access not specified");-
954 return false;
never executed: return false;
0
955 }-
956 if (d->openExternalFile(mode, fh, handleFlags)) {
d->openExterna..., handleFlags)Description
TRUEevaluated 364 times by 5 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
  • tst_qdbuscpp2xml - unknown status
  • tst_qdbusxml2cpp - unknown status
  • tst_qnetworkreply - unknown status
FALSEnever evaluated
0-364
957 QIODevice::open(mode);-
958 if (!(mode & Append) && !isSequential()) {
!(mode & Append)Description
TRUEevaluated 364 times by 5 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
  • tst_qdbuscpp2xml - unknown status
  • tst_qdbusxml2cpp - unknown status
  • tst_qnetworkreply - unknown status
FALSEnever evaluated
!isSequential()Description
TRUEevaluated 27 times by 2 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
FALSEevaluated 337 times by 4 tests
Evaluated by:
  • tst_QFile
  • tst_qdbuscpp2xml - unknown status
  • tst_qdbusxml2cpp - unknown status
  • tst_qnetworkreply - unknown status
0-364
959 qint64 pos = (qint64)QT_FTELL(fh);-
960 if (pos != -1) {
pos != -1Description
TRUEevaluated 27 times by 2 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
FALSEnever evaluated
0-27
961 // Skip redundant checks in QFileDevice::seek().-
962 QIODevice::seek(pos);-
963 }
executed 27 times by 2 tests: end of block
Executed by:
  • tst_LargeFile
  • tst_QFile
27
964 }
executed 27 times by 2 tests: end of block
Executed by:
  • tst_LargeFile
  • tst_QFile
27
965 return true;
executed 364 times by 5 tests: return true;
Executed by:
  • tst_LargeFile
  • tst_QFile
  • tst_qdbuscpp2xml - unknown status
  • tst_qdbusxml2cpp - unknown status
  • tst_qnetworkreply - unknown status
364
966 }-
967 return false;
never executed: return false;
0
968}-
969-
970/*!-
971 \overload-
972-
973 Opens the existing file descriptor \a fd in the given \a mode.-
974 \a handleFlags may be used to specify additional options.-
975 Returns \c true if successful; otherwise returns \c false.-
976-
977 When a QFile is opened using this function, behaviour of close() is-
978 controlled by the AutoCloseHandle flag.-
979 If AutoCloseHandle is specified, and this function succeeds,-
980 then calling close() closes the adopted handle.-
981 Otherwise, close() does not actually close the file, but only flushes it.-
982-
983 The QFile that is opened using this function is automatically set-
984 to be in raw mode; this means that the file input/output functions-
985 are slow. If you run into performance issues, you should try to-
986 use one of the other open functions.-
987-
988 \warning If \a fd is not a regular file, e.g, it is 0 (\c stdin),-
989 1 (\c stdout), or 2 (\c stderr), you may not be able to seek(). In-
990 those cases, size() returns \c 0. See QIODevice::isSequential()-
991 for more information.-
992-
993 \warning Since this function opens the file without specifying the file name,-
994 you cannot use this QFile with a QFileInfo.-
995-
996 \sa close()-
997*/-
998bool QFile::open(int fd, OpenMode mode, FileHandleFlags handleFlags)-
999{-
1000 Q_D(QFile);-
1001 if (isOpen()) {
isOpen()Description
TRUEnever evaluated
FALSEevaluated 29 times by 3 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
  • tst_QPrinterInfo
0-29
1002 qWarning("QFile::open: File (%s) already open", qPrintable(fileName()));-
1003 return false;
never executed: return false;
0
1004 }-
1005 if (mode & Append)
mode & AppendDescription
TRUEnever evaluated
FALSEevaluated 29 times by 3 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
  • tst_QPrinterInfo
0-29
1006 mode |= WriteOnly;
never executed: mode |= WriteOnly;
0
1007 unsetError();-
1008 if ((mode & (ReadOnly | WriteOnly)) == 0) {
(mode & (ReadO...iteOnly)) == 0Description
TRUEnever evaluated
FALSEevaluated 29 times by 3 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
  • tst_QPrinterInfo
0-29
1009 qWarning("QFile::open: File access not specified");-
1010 return false;
never executed: return false;
0
1011 }-
1012 if (d->openExternalFile(mode, fd, handleFlags)) {
d->openExterna..., handleFlags)Description
TRUEevaluated 29 times by 3 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
  • tst_QPrinterInfo
FALSEnever evaluated
0-29
1013 QIODevice::open(mode);-
1014 if (!(mode & Append) && !isSequential()) {
!(mode & Append)Description
TRUEevaluated 29 times by 3 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
  • tst_QPrinterInfo
FALSEnever evaluated
!isSequential()Description
TRUEevaluated 24 times by 2 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
FALSEevaluated 5 times by 2 tests
Evaluated by:
  • tst_QFile
  • tst_QPrinterInfo
0-29
1015 qint64 pos = (qint64)QT_LSEEK(fd, QT_OFF_T(0), SEEK_CUR);-
1016 if (pos != -1) {
pos != -1Description
TRUEevaluated 24 times by 2 tests
Evaluated by:
  • tst_LargeFile
  • tst_QFile
FALSEnever evaluated
0-24
1017 // Skip redundant checks in QFileDevice::seek().-
1018 QIODevice::seek(pos);-
1019 }
executed 24 times by 2 tests: end of block
Executed by:
  • tst_LargeFile
  • tst_QFile
24
1020 }
executed 24 times by 2 tests: end of block
Executed by:
  • tst_LargeFile
  • tst_QFile
24
1021 return true;
executed 29 times by 3 tests: return true;
Executed by:
  • tst_LargeFile
  • tst_QFile
  • tst_QPrinterInfo
29
1022 }-
1023 return false;
never executed: return false;
0
1024}-
1025-
1026/*!-
1027 \reimp-
1028*/-
1029bool QFile::resize(qint64 sz)-
1030{-
1031 return QFileDevice::resize(sz); // for now
executed 295 times by 7 tests: return QFileDevice::resize(sz);
Executed by:
  • tst_QAbstractFileEngine
  • tst_QDirModel
  • tst_QFile
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QNetworkReply
  • tst_QTemporaryFile
295
1032}-
1033-
1034/*!-
1035 \overload-
1036-
1037 Sets \a fileName to size (in bytes) \a sz. Returns \c true if the file if-
1038 the resize succeeds; false otherwise. If \a sz is larger than \a-
1039 fileName currently is the new bytes will be set to 0, if \a sz is-
1040 smaller the file is simply truncated.-
1041-
1042 \sa resize()-
1043*/-
1044-
1045bool-
1046QFile::resize(const QString &fileName, qint64 sz)-
1047{-
1048 return QFile(fileName).resize(sz);
executed 3 times by 1 test: return QFile(fileName).resize(sz);
Executed by:
  • tst_QFile
3
1049}-
1050-
1051/*!-
1052 \reimp-
1053*/-
1054QFile::Permissions QFile::permissions() const-
1055{-
1056 return QFileDevice::permissions(); // for now
executed 200 times by 12 tests: return QFileDevice::permissions();
Executed by:
  • tst_QFile
  • tst_QFileDialog2
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QIcon
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLocalSocket
  • tst_QMimeDatabase
  • tst_QSaveFile
  • tst_qmakelib
  • tst_qstandardpaths
200
1057}-
1058-
1059/*!-
1060 \overload-
1061-
1062 Returns the complete OR-ed together combination of-
1063 QFile::Permission for \a fileName.-
1064*/-
1065-
1066QFile::Permissions-
1067QFile::permissions(const QString &fileName)-
1068{-
1069 return QFile(fileName).permissions();
executed 11 times by 3 tests: return QFile(fileName).permissions();
Executed by:
  • tst_QFile
  • tst_QFileSystemModel
  • tst_QSaveFile
11
1070}-
1071-
1072/*!-
1073 Sets the permissions for the file to the \a permissions specified.-
1074 Returns \c true if successful, or \c false if the permissions cannot be-
1075 modified.-
1076-
1077 \warning This function does not manipulate ACLs, which may limit its-
1078 effectiveness.-
1079-
1080 \sa permissions(), setFileName()-
1081*/-
1082-
1083bool QFile::setPermissions(Permissions permissions)-
1084{-
1085 return QFileDevice::setPermissions(permissions); // for now
executed 622 times by 17 tests: return QFileDevice::setPermissions(permissions);
Executed by:
  • tst_QDir
  • tst_QDirModel
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QFileSystemWatcher
  • tst_QIcon
  • tst_QImageReader
  • tst_QImageWriter
  • tst_QLockFile
  • tst_QMimeDatabase
  • tst_QNetworkReply
  • tst_QSaveFile
  • tst_QSettings
  • tst_QTemporaryDir
  • tst_qmakelib
  • tst_qstandardpaths
622
1086}-
1087-
1088/*!-
1089 \overload-
1090-
1091 Sets the permissions for \a fileName file to \a permissions.-
1092*/-
1093-
1094bool-
1095QFile::setPermissions(const QString &fileName, Permissions permissions)-
1096{-
1097 return QFile(fileName).setPermissions(permissions);
executed 159 times by 6 tests: return QFile(fileName).setPermissions(permissions);
Executed by:
  • tst_QFile
  • tst_QFileInfo
  • tst_QFileSystemModel
  • tst_QIcon
  • tst_QImageReader
  • tst_QMimeDatabase
159
1098}-
1099-
1100/*!-
1101 \reimp-
1102*/-
1103qint64 QFile::size() const-
1104{-
1105 return QFileDevice::size(); // for now
executed 165638 times by 164 tests: return QFileDevice::size();
Executed by:
  • tst_LargeFile
  • tst_NetworkSelfTest
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QChar
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCryptographicHash
  • tst_QCssParser
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDebug
  • tst_QDialog
  • ...
165638
1106}-
1107-
1108QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9