ErrorCollector

Description

The ErrorCollector object collects errors from a list of objects and triggers an internal event populated with the data of the most recently occurred error. The object has to be a children of an EventLog object so that the internal event is sent to the configured EventLog.outputs.

› Inherits:EventLogItem

Properties

currentEvent

This property holds an Event object which represents the most recently occurred error. While most properties are set and updated internally, the Event.severity property can be changed to a custom value. This way the filtering and processing of error events in EventOutput objects can be customized. Per default the severity of this event is set to Event.Error.

› Type:Event
› Signal:currentEventChanged()
› Attributes:Readonly

objects

This property holds a list of objects to monitor for errors. The monitored objects need to have at least one of the properties error or errorString and should have an errorOccurred() signal. See the example for information on how to add such properties and signals in custom objects.

› Type:List
› Signal:objectsChanged()
› Attributes:Writable

Example

import InCore.Foundation 2.5

Application {

    File {
        // file without storage will raise an error when opened
        id: file
        fileName: "test.txt"
    }

    // polling on property which does not support polling will an raise error
    Polling on name {
        id: polling
        interval: 1000
    }

    // create custom object with errorString property
    Object {
        id: customObject
        property string errorString;

        function doSomething() {
            errorString = "Something bad happened";
        }
    }

    // create custom object with errorOccurred signal - the event description will be empty due to the
    // missing errorString property
    Object {
        id: customObjectWithSignal
        signal errorOccurred();

        function doSomething() {
            errorOccurred()
        }
    }

    EventLog {
        // print events to console
        outputs: [ EventJournal { } ]

        // collect errors from objects defined above
        ErrorCollector {
            objects: [ file, sms, polling, customObject, customObjectWithSignal ]
        }
    }

    onCompleted: {
        // trigger errors
        file.open();
        customObject.doSomething()
        customObjectWithSignal.doSomething()
    }
}