UsbStorage
Description
The UsbStorage object is a Storage object which provides access to a USB drive connected to the local device. Whenever a USB drive is detected by the system, the UsbStorage object mounts it automatically and updates the Storage.available property. When writing files to a USB drive make sure to call eject() before allowing the user to unplug the drive.
- › Inherits:
Overview
Properties
Methods
Signals
Enumerations
Properties
error
This property holds the most recently occurred error or UsbStorage.NoError if no error occurred. If the same error occurs multiple times this property does not change. Use the errorOccurred() signal to detect multiple occurrences of the same error.
- › Type:
- › Signal:
errorChanged()
- › Attributes:
Readonly
errorString
This property holds the current human readable error string corresponding to the current value in the error property. It may include additional information such as failure reasons or locations.
- › Type:
String
- › Signal:
errorStringChanged()
- › Attributes:
Readonly
Methods
eject()
This method writes all pending data to the USB drive and unmounts it so it can be removed safely. After unmounting it’s not accessible any longer until the USB drive is physically plugged in again.
- › Returns:
Boolean
sync()
This method writes all pending data (i.e. write buffers/caches) to the USB drive.
Signals
errorOccurred()
This signal is emitted whenever an error has occurred, regardless of whether the error property has changed or not. In contrast to the change notification signal of the error property this signal is also emitted several times if a certain error occurs several times in succession.
Enumerations
Error
This enumeration describes all errors which can occur in UsbStorage objects. The most recently occurred error is stored in the error property.
Name |
Value |
Description |
|---|---|---|
|
|
No error occurred or was detected. |
|
|
Error while mounting USB drive (). |
Example
import InCore.Foundation 2.5
Application {
CsvWriter {
id: csvWriter
// create fictional measurements
Repeater on objects {
model: 3
Measurement {
name: "meas" + index
data: index
}
}
// write one data row to CSV file to USB drive whenever it is plugged in and eject it afterwards
output: File {
fileName: "measurements.csv"
storage: UsbStorage {
onAvailableChanged: {
csvWriter.submit()
eject();
}
}
}
}
}