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

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