.. _object_CsvWriter: :index:`CsvWriter` ------------------ Description *********** The CsvWriter object is a special :ref:`DataObjectWriter ` designed to write datasets as rows containing comma-separated values to an :ref:`output `, usually a :ref:`File `. The format of the output data can be configured through the :ref:`delimiter ` and :ref:`writeHeader ` properties. :**› Inherits**: :ref:`DataObjectWriter ` Overview ******** Properties ++++++++++ .. hlist:: :columns: 3 * :ref:`delimiter ` * :ref:`error ` * :ref:`errorString ` * :ref:`output ` * :ref:`outputMode ` * :ref:`rotationMode ` * :ref:`writeByteOrderMark ` * :ref:`writeHeader ` * :ref:`DataObjectWriter.datasetCount ` * :ref:`DataObjectWriter.objects ` * :ref:`DataObjectWriter.running ` * :ref:`DataObjectWriter.submitChangedObjectsOnly ` * :ref:`DataObjectWriter.submitInterval ` * :ref:`DataObjectWriter.submitMode ` * :ref:`Object.objectId ` * :ref:`Object.parent ` Methods +++++++ .. hlist:: :columns: 2 * :ref:`DataObjectWriter.close() ` * :ref:`DataObjectWriter.open() ` * :ref:`DataObjectWriter.submit() ` * :ref:`DataObjectWriter.sync() ` * :ref:`DataObjectWriter.truncate() ` * :ref:`Object.deserializeProperties() ` * :ref:`Object.fromJson() ` * :ref:`Object.serializeProperties() ` * :ref:`Object.toJson() ` Signals +++++++ .. hlist:: :columns: 1 * :ref:`errorOccurred() ` * :ref:`DataObjectWriter.objectsDataChanged() ` * :ref:`DataObjectWriter.submitted() ` * :ref:`DataObjectWriter.truncated() ` * :ref:`Object.completed() ` Enumerations ++++++++++++ .. hlist:: :columns: 1 * :ref:`Error ` * :ref:`OutputMode ` * :ref:`RotationMode ` * :ref:`DataObjectWriter.SubmitMode ` Properties ********** .. _property_CsvWriter_delimiter: .. _signal_CsvWriter_delimiterChanged: .. index:: single: delimiter delimiter +++++++++ This property holds the delimiter for separating columns in a data row. :**› Type**: String :**› Default**: ``;`` :**› Signal**: delimiterChanged() :**› Attributes**: Writable .. _property_CsvWriter_error: .. _signal_CsvWriter_errorChanged: .. index:: single: error error +++++ This property holds the most recently occurred error or :ref:`CsvWriter.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_CsvWriter_errorString: .. _signal_CsvWriter_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_CsvWriter_output: .. _signal_CsvWriter_outputChanged: .. index:: single: output output ++++++ This property holds the output device which the CSV data is written to. Usually a :ref:`File ` object should be used here. :**› Type**: :ref:`IoDevice ` :**› Signal**: outputChanged() :**› Attributes**: Writable .. _property_CsvWriter_outputMode: .. _signal_CsvWriter_outputModeChanged: .. index:: single: outputMode outputMode ++++++++++ This property holds the output mode which defines how new rows are written to the output. See the :ref:`OutputMode ` enumeration for details. :**› Type**: :ref:`OutputMode ` :**› Default**: :ref:`CsvWriter.OutputAppend ` :**› Signal**: outputModeChanged() :**› Attributes**: Writable .. _property_CsvWriter_rotationMode: .. _signal_CsvWriter_rotationModeChanged: .. index:: single: rotationMode rotationMode ++++++++++++ This property holds the rotation mode which allows rotating files periodically in an automated manner. On every data row submission the :ref:`CsvWriter ` checks whether a rotation period is elapsed and if necessary closes the current file and opens a file for the new period. The name of the file depends on the configured rotation mode. See the :ref:`RotationMode ` enumeration for details. :**› Type**: :ref:`RotationMode ` :**› Default**: :ref:`CsvWriter.NoRotation ` :**› Signal**: rotationModeChanged() :**› Attributes**: Writable .. _property_CsvWriter_writeByteOrderMark: .. _signal_CsvWriter_writeByteOrderMarkChanged: .. index:: single: writeByteOrderMark writeByteOrderMark ++++++++++++++++++ This property holds whether to write the `Byte Order Mark (BOM) `_ ``EF BB BF`` as the first characters to the output. These BOM characters indicate that UTF-8 encoding should be used when reading the file. This property was introduced in InCore 2.1. :**› Type**: Boolean :**› Default**: ``false`` :**› Signal**: writeByteOrderMarkChanged() :**› Attributes**: Writable .. _property_CsvWriter_writeHeader: .. _signal_CsvWriter_writeHeaderChanged: .. index:: single: writeHeader writeHeader +++++++++++ This property holds whether to write a header with the column names (:ref:`DataObject.name `) to the output. :**› Type**: Boolean :**› Default**: ``true`` :**› Signal**: writeHeaderChanged() :**› Attributes**: Writable Signals ******* .. _signal_CsvWriter_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_CsvWriter_Error: .. index:: single: Error Error +++++ This enumeration describes all errors which can occur in CsvWriter objects. The most recently occurred error is stored in the :ref:`error ` property. .. index:: single: CsvWriter.NoError .. index:: single: CsvWriter.OutputNotSetError .. index:: single: CsvWriter.OutputOpenError .. list-table:: :widths: auto :header-rows: 1 * - Name - Value - Description .. _enumitem_CsvWriter_NoError: * - ``CsvWriter.NoError`` - ``0`` - No error occurred or was detected. .. _enumitem_CsvWriter_OutputNotSetError: * - ``CsvWriter.OutputNotSetError`` - ``1`` - Output not set. .. _enumitem_CsvWriter_OutputOpenError: * - ``CsvWriter.OutputOpenError`` - ``2`` - Could not open output. .. _enum_CsvWriter_OutputMode: .. index:: single: OutputMode OutputMode ++++++++++ This enumeration describes the output mode which defines how new rows are written to the output. .. index:: single: CsvWriter.OutputAppend .. index:: single: CsvWriter.OutputTruncate .. index:: single: CsvWriter.OutputCustom .. list-table:: :widths: auto :header-rows: 1 * - Name - Value - Description .. _enumitem_CsvWriter_OutputAppend: * - ``CsvWriter.OutputAppend`` - ``0`` - Always append rows to the output. This mode sets the :ref:`IoDevice.append ` property to ``true`` and clears the :ref:`IoDevice.truncate ` and :ref:`IoDevice.unbuffered ` properties. .. _enumitem_CsvWriter_OutputTruncate: * - ``CsvWriter.OutputTruncate`` - ``1`` - Truncate the output on every submission to make it always contain only one row with the latest data. This mode clears the :ref:`IoDevice.append ` property and sets the :ref:`IoDevice.truncate ` and :ref:`IoDevice.unbuffered ` properties to ``true``. .. _enumitem_CsvWriter_OutputCustom: * - ``CsvWriter.OutputCustom`` - ``2`` - Open the output without changing the :ref:`IoDevice.append `, :ref:`IoDevice.truncate ` and :ref:`IoDevice.unbuffered ` properties. This allows implementing a custom output mode by setting these properties manually. .. _enum_CsvWriter_RotationMode: .. index:: single: RotationMode RotationMode ++++++++++++ This enumeration describes all supported modes for rotating files periodically. .. index:: single: CsvWriter.NoRotation .. index:: single: CsvWriter.RotateMinutely .. index:: single: CsvWriter.RotateHourly .. index:: single: CsvWriter.RotateDaily .. index:: single: CsvWriter.RotateWeekly .. index:: single: CsvWriter.RotateMonthly .. index:: single: CsvWriter.RotateYearly .. list-table:: :widths: auto :header-rows: 1 * - Name - Value - Description .. _enumitem_CsvWriter_NoRotation: * - ``CsvWriter.NoRotation`` - ``0`` - Disable periodical file rotation. .. _enumitem_CsvWriter_RotateMinutely: * - ``CsvWriter.RotateMinutely`` - ``1`` - Rotate every minute with file suffix ``. .. _enumitem_CsvWriter_RotateHourly: * - ``CsvWriter.RotateHourly`` - ``2`` - Rotate every hour with file suffix ``. .. _enumitem_CsvWriter_RotateDaily: * - ``CsvWriter.RotateDaily`` - ``3`` - Rotate every day with file suffix ``. .. _enumitem_CsvWriter_RotateWeekly: * - ``CsvWriter.RotateWeekly`` - ``4`` - Rotate every week with file suffix ``. .. _enumitem_CsvWriter_RotateMonthly: * - ``CsvWriter.RotateMonthly`` - ``5`` - Rotate every month with file suffix ``. .. _enumitem_CsvWriter_RotateYearly: * - ``CsvWriter.RotateYearly`` - ``6`` - Rotate every year with file suffix ``. .. _example_CsvWriter: Example ******* .. code-block:: qml import InCore.Foundation 2.5 Application { // record measurements and append new lines after all data objects have been updated CsvWriter { id: writer1 Repeater on objects { model: 3 Measurement { id: measurement name: "meas" + index property var updateTimer : Timer { interval: 1000 running: true onTriggered: measurement.data = Math.random() * 100; } } } output: File { fileName: "all-values.csv" storage: LocalStorage { } } outputMode: CsvWriter.OutputAppend submitMode: CsvWriter.SubmitOnCompleteDataset } // continuously update a file in memory which always contains only one line with the most recent values CsvWriter { objects: writer1.objects output: File { unbuffered: true fileName: "current-values.txt" storage: InMemoryStorage { } } writeHeader: false delimiter: " " outputMode: CsvWriter.OutputTruncate submitMode: CsvWriter.SubmitOnAnyChange } }