.. _object_File: :index:`File` ------------- Description *********** The File object is an :ref:`IoDevice ` object allowing to :ref:`read `,:ref:`write ` and :ref:`remove ` files. In general a file is always stored on a certain :ref:`storage ` which also predefines the absolute path to the file. A relative path (i.e. subdirectories) may be included in the :ref:`file name `. :**› Inherits**: :ref:`IoDevice ` Overview ******** Properties ++++++++++ .. hlist:: :columns: 3 * :ref:`error ` * :ref:`errorString ` * :ref:`fileName ` * :ref:`storage ` * :ref:`IoDevice.append ` * :ref:`IoDevice.atEnd ` * :ref:`IoDevice.autoOpen ` * :ref:`IoDevice.bytesAvailable ` * :ref:`IoDevice.canReadLine ` * :ref:`IoDevice.deviceErrorString ` * :ref:`IoDevice.isOpen ` * :ref:`IoDevice.isWritable ` * :ref:`IoDevice.nameArgument ` * :ref:`IoDevice.pos ` * :ref:`IoDevice.readOnly ` * :ref:`IoDevice.size ` * :ref:`IoDevice.truncate ` * :ref:`IoDevice.unbuffered ` * :ref:`Object.objectId ` * :ref:`Object.parent ` Methods +++++++ .. hlist:: :columns: 3 * :ref:`remove() ` * :ref:`sync() ` * :ref:`IoDevice.close() ` * :ref:`IoDevice.flush() ` * :ref:`IoDevice.open() ` * :ref:`IoDevice.peekAll() ` * :ref:`IoDevice.read() ` * :ref:`IoDevice.readAll() ` * :ref:`IoDevice.readLine() ` * :ref:`IoDevice.sync() ` * :ref:`IoDevice.write() ` * :ref:`Object.deserializeProperties() ` * :ref:`Object.fromJson() ` * :ref:`Object.serializeProperties() ` * :ref:`Object.toJson() ` Signals +++++++ .. hlist:: :columns: 1 * :ref:`errorOccurred() ` * :ref:`IoDevice.lineAvailableForRead() ` * :ref:`IoDevice.readyRead() ` * :ref:`Object.completed() ` Enumerations ++++++++++++ .. hlist:: :columns: 1 * :ref:`Error ` Properties ********** .. _property_File_error: .. _signal_File_errorChanged: .. index:: single: error error +++++ This property holds the most recently occurred error or :ref:`File.NoError ` if no error occurred. If the same error occurs multiple times this property does not change. Use the :ref:`errorOccurred() ` signal to detect multiple occurrences of the same error. :**› Type**: :ref:`Error ` :**› Signal**: errorChanged() :**› Attributes**: Readonly .. _property_File_errorString: .. _signal_File_errorStringChanged: .. index:: single: errorString errorString +++++++++++ This property holds the current human readable error string corresponding to the current value in the :ref:`error ` property. It may include additional information such as failure reasons or locations. :**› Type**: String :**› Signal**: errorStringChanged() :**› Attributes**: Readonly .. _property_File_fileName: .. _signal_File_fileNameChanged: .. index:: single: fileName fileName ++++++++ This property holds the name of the file. It is always relative to the :ref:`storage ` which this file is stored on. The file name has to be set before the file is :ref:`opened `. :**› Type**: String :**› Signal**: fileNameChanged() :**› Attributes**: Writable .. _property_File_storage: .. _signal_File_storageChanged: .. index:: single: storage storage +++++++ This property holds a reference to the storage which the file is stored on. It has to be set before the file is :ref:`opened `. :**› Type**: :ref:`Storage ` :**› Signal**: storageChanged() :**› Attributes**: Writable Methods ******* .. _method_File_remove: .. index:: single: remove remove() ++++++++ This method removes the file specified by :ref:`fileName ` and stored on :ref:`storage `. :**› Returns**: Boolean .. _method_File_sync: .. index:: single: sync sync() ++++++ This method calls :ref:`IoDevice.flush() ` and tells the operating system to write all pending data to its storages. Calling this method might block the program execution for a while depending on the amount of data to be written. Signals ******* .. _signal_File_errorOccurred: .. index:: single: errorOccurred errorOccurred() +++++++++++++++ This signal is emitted whenever an error has occurred, regardless of whether the :ref:`error ` property has changed or not. In contrast to the change notification signal of the :ref:`error ` property this signal is also emitted several times if a certain error occurs several times in succession. Enumerations ************ .. _enum_File_Error: .. index:: single: Error Error +++++ This enumeration describes all errors which can occur in File objects. The most recently occurred error is stored in the :ref:`error ` property. .. index:: single: File.NoError .. index:: single: File.InvalidStorageError .. index:: single: File.StoragePathError .. index:: single: File.OpenError .. list-table:: :widths: auto :header-rows: 1 * - Name - Value - Description .. _enumitem_File_NoError: * - ``File.NoError`` - ``0`` - No error occurred or was detected. .. _enumitem_File_InvalidStorageError: * - ``File.InvalidStorageError`` - ``1`` - None or invalid storage set. .. _enumitem_File_StoragePathError: * - ``File.StoragePathError`` - ``2`` - Error while creating directories on storage. .. _enumitem_File_OpenError: * - ``File.OpenError`` - ``3`` - Error while opening file likely due to permission problem.