Solid::Device Class

class Solid::Device

This class allows applications to deal with devices available in the underlying system. More...

Header: #include <Solid/Device>
CMake: find_package(KF6 REQUIRED COMPONENTS Solid)
target_link_libraries(mytarget PRIVATE KF6::Solid)

Public Functions

Device(const QString &udi = QString())
DevIface *as()
const DevIface *as() const
Solid::DeviceInterface *asDeviceInterface(const Solid::DeviceInterface::Type &type)
const Solid::DeviceInterface *asDeviceInterface(const Solid::DeviceInterface::Type &type) const
(since 4.4) QString description() const
(since 5.71) QString displayName() const
(since 4.4) QStringList emblems() const
QString icon() const
bool is() const
bool isDeviceInterface(const Solid::DeviceInterface::Type &type) const
bool isValid() const
Solid::Device parent() const
QString parentUdi() const
QString product() const
QString udi() const
QString vendor() const

Static Public Members

QList<Solid::Device> allDevices()
QList<Solid::Device> listFromQuery(const QString &predicate, const QString &parentUdi = QString())
QList<Solid::Device> listFromQuery(const Solid::Predicate &predicate, const QString &parentUdi = QString())
QList<Solid::Device> listFromType(const Solid::DeviceInterface::Type &type, const QString &parentUdi = QString())
(since 5.73) Solid::Device storageAccessFromPath(const QString &path)

Detailed Description

Device stores a reference to device data provided by the backend. Device objects are designed to be used by value. Copying these objects is quite cheap, so using pointers to the me is generally not needed.

Member Function Documentation

[explicit] Device::Device(const QString &udi = QString())

Constructs a device for a given Universal Device Identifier (UDI).

udi the udi of the device to create

[static] QList<Solid::Device> Device::allDevices()

Retrieves all the devices available in the underlying system.

Returns the list of the devices available

template <typename DevIface> DevIface *Device::as()

Retrieves a specialized interface to interact with the device corresponding to a given device interface.

Returns a pointer to the device interface if it exists, 0 otherwise

template <typename DevIface> const DevIface *Device::as() const

Retrieves a specialized interface to interact with the device corresponding to a given device interface.

Returns a pointer to the device interface if it exists, 0 otherwise

Solid::DeviceInterface *Device::asDeviceInterface(const Solid::DeviceInterface::Type &type)

Retrieves a specialized interface to interact with the device corresponding to a particular device interface.

type the device interface type

Returns a pointer to the device interface interface if it exists, 0 otherwise

const Solid::DeviceInterface *Device::asDeviceInterface(const Solid::DeviceInterface::Type &type) const

Retrieves a specialized interface to interact with the device corresponding to a particular device interface.

type the device interface type

Returns a pointer to the device interface interface if it exists, 0 otherwise

[since 4.4] QString Device::description() const

Retrieves the description of device.

Returns the description

This function was introduced in 4.4.

[since 5.71] QString Device::displayName() const

Retrieves the display Name to use for this device. Same as description when not defined.

Returns the display Name

This function was introduced in 5.71.

[since 4.4] QStringList Device::emblems() const

Retrieves the names of the emblems representing the state of this device. The naming follows the freedesktop.org specification.

Returns the emblem names

This function was introduced in 4.4.

QString Device::icon() const

Retrieves the name of the icon representing this device. The naming follows the freedesktop.org specification.

Returns the icon name

template <typename DevIface> bool Device::is() const

Tests if a device provides a given device interface.

Returns true if the interface is available, false otherwise

bool Device::isDeviceInterface(const Solid::DeviceInterface::Type &type) const

Tests if a device interface is available from the device.

type the device interface type to query

Returns true if the device interface is available, false otherwise

bool Device::isValid() const

Indicates if this device is valid.

A device is considered valid if it's available in the system.

Returns true if this device is available, false otherwise

[static] QList<Solid::Device> Device::listFromQuery(const QString &predicate, const QString &parentUdi = QString())

Convenience function see above.

Returns the list of devices

[static] QList<Solid::Device> Device::listFromQuery(const Solid::Predicate &predicate, const QString &parentUdi = QString())

Retrieves a list of devices of the system given matching the given constraints (parent and predicate)

predicate Predicate that the devices we're searching for must verify

parentUdi UDI of the parent of the devices we're searching for, or QString() if there's no constraint on the parent

Returns the list of devices corresponding to the given constraints

See also Solid::Predicate.

[static] QList<Solid::Device> Device::listFromType(const Solid::DeviceInterface::Type &type, const QString &parentUdi = QString())

Retrieves a list of devices of the system given matching the given constraints (parent and device interface type)

type device interface type available on the devices we're looking for, or DeviceInterface::Unknown if there's no constraint on the device interfaces

parentUdi UDI of the parent of the devices we're searching for, or QString() if there's no constraint on the parent

Returns the list of devices corresponding to the given constraints

See also Solid::Predicate.

Solid::Device Device::parent() const

Retrieves the parent of the Device.

Returns the device's parent

See also parentUdi().

QString Device::parentUdi() const

Retrieves the Universal Device Identifier (UDI) of the Device's parent.

Returns the udi of the device's parent

QString Device::product() const

Retrieves the name of the product corresponding to this device.

Returns the product name

[static, since 5.73] Solid::Device Device::storageAccessFromPath(const QString &path)

Returns the Device containing the filesystem for the given path

canonical path to a filesystem entry, e.g. a file or directory

Returns a Device containing the given path.

For Devices implementing the StorageVolume interface only ones matching UsageType::FileSystem are returned, i.e. no backing encrypted volumes.

This function was introduced in 5.73.

See also QFileInfo::canonicalFilePath.

QString Device::udi() const

Retrieves the Universal Device Identifier (UDI).

Warning: Don't use the UDI for anything except communication with Solid. Also don't store UDIs as there's no guarantee that the UDI stays the same when the hardware setup changed. The UDI is a unique identifier that is local to the computer in question and for the current boot session. The UDIs may change after a reboot. Similar hardware in other computers may have different values; different hardware could have the same UDI.

Returns the udi of the device

QString Device::vendor() const

Retrieves the name of the device vendor.

Returns the vendor name