QBatteryInfo Class
The QBatteryInfo class provides various information about the batteries. More...
Header: | #include <QBatteryInfo> |
Public Types
enum | ChargerType { UnknownCharger, WallCharger, USBCharger, VariableCurrentCharger } |
enum | ChargingState { UnknownChargingState, Charging, IdleChargingState, Discharging } |
enum | Health { HealthUnknown, HealthOk, HealthBad } |
enum | LevelStatus { LevelUnknown, LevelEmpty, LevelLow, LevelOk, LevelFull } |
Properties
|
|
Public Functions
QBatteryInfo(int batteryIndex, QObject *parent = Q_NULLPTR) | |
QBatteryInfo(QObject *parent = Q_NULLPTR) | |
virtual | ~QBatteryInfo() |
int | batteryCount() const |
int | batteryIndex() const |
QBatteryInfo::ChargerType | chargerType() const |
QBatteryInfo::ChargingState | chargingState() const |
int | currentFlow() const |
int | cycleCount() const |
QBatteryInfo::Health | health() const |
bool | isValid() const |
int | level() const |
QBatteryInfo::LevelStatus | levelStatus() const |
int | maximumCapacity() const |
int | remainingCapacity() const |
int | remainingChargingTime() const |
void | setBatteryIndex(int batteryIndex) |
float | temperature() const |
int | voltage() const |
Signals
void | batteryCountChanged(int count) |
void | batteryIndexChanged(int batteryIndex) |
void | chargerTypeChanged(QBatteryInfo::ChargerType type) |
void | chargingStateChanged(QBatteryInfo::ChargingState state) |
void | currentFlowChanged(int flow) |
void | cycleCountChanged(int cycleCount) |
void | healthChanged(QBatteryInfo::Health health) |
void | levelChanged(int level) |
void | levelStatusChanged(QBatteryInfo::LevelStatus levelStatus) |
void | remainingCapacityChanged(int capacity) |
void | remainingChargingTimeChanged(int seconds) |
void | temperatureChanged(float temperature) |
void | validChanged(bool isValid) |
void | voltageChanged(int voltage) |
Detailed Description
Note that on some platforms, listening to the signals could lead to a heavy CPU usage. Therefore, you are strongly suggested to disconnect the signals when no longer needed in your application.
Battery index starts at 0
, which indicates the first battery.
Member Type Documentation
enum QBatteryInfo::ChargerType
This enum describes the type of charger used.
Constant | Value | Description |
---|---|---|
QBatteryInfo::UnknownCharger | 0 | The charger type is unknown, or no charger. |
QBatteryInfo::WallCharger | 1 | Using wall (mains) charger. |
QBatteryInfo::USBCharger | 2 | Using USB charger when the system cannot differentiate the current. |
QBatteryInfo::VariableCurrentCharger | 3 | Using variable current charger such as bicycle or solar. |
enum QBatteryInfo::ChargingState
This enum describes the charging state.
Constant | Value | Description |
---|---|---|
QBatteryInfo::UnknownChargingState | 0 | The charging state is unknown or charging error occured. |
QBatteryInfo::Charging | 1 | The battery is charging. |
QBatteryInfo::IdleChargingState | 2 | The battery is idle (neither Charging nor Discharging) |
QBatteryInfo::Discharging | 3 | The battery is discharging. |
enum QBatteryInfo::Health
This enum describes the health of the battery.
Constant | Value | Description |
---|---|---|
QBatteryInfo::HealthUnknown | 0 | Battery health undetermined |
QBatteryInfo::HealthOk | 1 | Battery health is OK |
QBatteryInfo::HealthBad | 2 | Battery health is bad |
enum QBatteryInfo::LevelStatus
This enum describes the level status of the battery.
Constant | Value | Description |
---|---|---|
QBatteryInfo::LevelUnknown | 0 | Battery level undetermined. |
QBatteryInfo::LevelEmpty | 1 | Battery is considered be empty and device needs to shut down. |
QBatteryInfo::LevelLow | 2 | Battery level is low and warnings need to be issued to the user. |
QBatteryInfo::LevelOk | 3 | Battery level is Ok. It is above "Low" but not "Full". |
QBatteryInfo::LevelFull | 4 | Battery is fully charged. |
Property Documentation
batteryCount : const int
This property holds the number of batteries available.
In case of an error or if the information is not available -1
is returned.
Access functions:
int | batteryCount() const |
Notifier signal:
void | batteryCountChanged(int count) |
batteryIndex : int
This property holds the current battery index
The first battery is represented by 0
.
Access functions:
int | batteryIndex() const |
void | setBatteryIndex(int batteryIndex) |
Notifier signal:
void | batteryIndexChanged(int batteryIndex) |
chargerType : const ChargerType
This property holds the type of the charger
Access functions:
QBatteryInfo::ChargerType | chargerType() const |
Notifier signal:
void | chargerTypeChanged(QBatteryInfo::ChargerType type) |
chargingState : const ChargingState
This property holds the charging state of the battery
Access functions:
QBatteryInfo::ChargingState | chargingState() const |
Notifier signal:
void | chargingStateChanged(QBatteryInfo::ChargingState state) |
currentFlow : const int
This property holds the current flow of the battery
This value is measured in milliamperes (mA). A positive returned value means the battery is discharging, while a negative value means the battery is charging. In case of an error or if the information is not available 0
is returned.
Access functions:
int | currentFlow() const |
Notifier signal:
void | currentFlowChanged(int flow) |
cycleCount : const int
This property holds the cycle count of the battery
In case of an error or if the information is not available -1
is returned.
Access functions:
int | cycleCount() const |
Notifier signal:
void | cycleCountChanged(int cycleCount) |
health : const Health
This property holds the health of the battery
Access functions:
QBatteryInfo::Health | health() const |
Notifier signal:
void | healthChanged(QBatteryInfo::Health health) |
level : const int
This property holds the level of the battery as a percentage
In case of an error or if the information is not available -1
is returned.
Access functions:
int | level() const |
Notifier signal:
void | levelChanged(int level) |
See also maximumCapacity(), remainingCapacity(), and levelStatus().
levelStatus : const LevelStatus
This property holds the level status of the battery
This represents an Empty/Low/Full style representation of the level().
Access functions:
QBatteryInfo::LevelStatus | levelStatus() const |
Notifier signal:
void | levelStatusChanged(QBatteryInfo::LevelStatus levelStatus) |
See also maximumCapacity(), remainingCapacity(), and level().
maximumCapacity : const int
This property holds the maximum capacity of the battery
This value is measured in mAh. In case of an error or if the information is not available -1
is returned.
Access functions:
int | maximumCapacity() const |
See also remainingCapacity(), level(), and levelStatus().
remainingCapacity : const int
This property holds the remaining capacity of the battery
This value is measured in mAh. In case of an error or if the information is not available -1
is returned.
Access functions:
int | remainingCapacity() const |
Notifier signal:
void | remainingCapacityChanged(int capacity) |
See also maximumCapacity(), level(), and levelStatus().
remainingChargingTime : const int
This property holds the remaining charging time needed for the battery
This value is measured in seconds. If the battery is full or not charging 0
is returned. In case of an error or if the information is not available -1
is returned.
Access functions:
int | remainingChargingTime() const |
Notifier signal:
void | remainingChargingTimeChanged(int seconds) |
temperature : const float
This property holds the temperature of the battery
This value is measured in Celsius. In case of an error or if the information is not available, NaN
is returned.
Access functions:
float | temperature() const |
Notifier signal:
void | temperatureChanged(float temperature) |
See also qQNaN().
valid : const bool
This property holds the validity of this instance
If this property returns false
batteryIndex() is the only other method that will return a valid value. All other methods will return default or invalid values and should not be relied upon for displaying to the user or for comparisons.
Access functions:
bool | isValid() const |
Notifier signal:
void | validChanged(bool isValid) |
voltage : const int
This property holds the voltage of the battery
This value is measured in millivolts (mV). In case of an error or if the information is not available -1
is returned.
Access functions:
int | voltage() const |
Notifier signal:
void | voltageChanged(int voltage) |
Member Function Documentation
QBatteryInfo::QBatteryInfo(int batteryIndex, QObject *parent = Q_NULLPTR)
Constructs a QBatteryInfo object with the given batteryIndex and parent.
QBatteryInfo::QBatteryInfo(QObject *parent = Q_NULLPTR)
Constructs a QBatteryInfo object with the given parent. The batteryIndex() will default to 0
.
[virtual]
QBatteryInfo::~QBatteryInfo()
Destroys the object