继承者: QAccelerometer , QAltimeter , QAmbientLightSensor , QAmbientTemperatureSensor , QCompass , QDistanceSensor , QGyroscope , QHolsterSensor , QHumiditySensor , QIRProximitySensor , QLidSensor , QLightSensor , QMagnetometer , QOrientationSensor , QPressureSensor , QProximitySensor , QRotationSensor , QTapSensor , QTiltSensor
def
addFilter
(filter)
def
availableDataRates
()
def
axesOrientationMode
()
def
backend
()
def
bufferSize
()
def
connectToBackend
()
def
currentOrientation
()
def
dataRate
()
def
description
()
def
efficientBufferSize
()
def
error
()
def
filters
()
def
identifier
()
def
isActive
()
def
isAlwaysOn
()
def
isBusy
()
def
isConnectedToBackend
()
def
isFeatureSupported
(feature)
def
maxBufferSize
()
def
outputRange
()
def
outputRanges
()
def
reading
()
def
removeFilter
(filter)
def
setActive
(active)
def
setAlwaysOn
(alwaysOn)
def
setAxesOrientationMode
(axesOrientationMode)
def
setBufferSize
(bufferSize)
def
setCurrentOrientation
(currentOrientation)
def
setDataRate
(rate)
def
setEfficientBufferSize
(efficientBufferSize)
def
setIdentifier
(identifier)
def
setMaxBufferSize
(maxBufferSize)
def
setOutputRange
(index)
def
setSkipDuplicates
(skipDuplicates)
def
setUserOrientation
(userOrientation)
def
skipDuplicates
()
def
type
()
def
userOrientation
()
def
activeChanged
()
def
alwaysOnChanged
()
def
availableSensorsChanged
()
def
axesOrientationModeChanged
(axesOrientationMode)
def
bufferSizeChanged
(bufferSize)
def
busyChanged
()
def
currentOrientationChanged
(currentOrientation)
def
dataRateChanged
()
def
efficientBufferSizeChanged
(efficientBufferSize)
def
maxBufferSizeChanged
(maxBufferSize)
def
readingChanged
()
def
sensorError
(error)
def
skipDuplicatesChanged
(skipDuplicates)
def
userOrientationChanged
(userOrientation)
def
defaultSensorForType
(type)
def
sensorTypes
()
def
sensorsForType
(type)
通常,传感器的生命周期为:
Create a sub-class of
QSensoron the stack or heap.通过应用程序按要求设置。
开始接收值。
通过应用程序使用传感器数据。
停止接收值。
交付传感器数据凭借
QSensorReading及其子类。
Some sensors react to screen orientation changes, such as
QAccelerometer,QMagnetometerandQRotationSensor. These are so called orientable sensors. For orientable sensors,QSensorsupports changing the reporting of the reading values based on the orientation of the screen.For orientable sensors, the
axesOrientationModeproperty controls how the orientation affects the reading values.In the default mode,
FixedOrientation, the reading values remain unaffected by the orientation. In theAutomaticOrientationmode, the reading values are automatically rotated by taking the current screen orientation into account. And finally, in theUserOrientationmode, the reading values are rotated according to a user-specified orientation.The functionality of this is only available if it is supported by the backend and if the sensor is orientable, which can be checked by calling
isFeatureSupported()采用AxesOrientation标志。The orientation values here are always of the screen orientation, not the device orientation. The screen orientation is the orientation of the GUI. For example when rotating a device by 90 degrees counter-clockwise, the screen orientation compensates for that by rotating 90 degrees clockwise, to the effect that the GUI is still facing upright after the device has been rotated. Note that applications can lock the screen orientation, for example to force portrait or landscape mode. For locked orientations, orientable sensors will not react with reading changes if the device orientation is changed, as orientable sensors react to screen orientation changes only. This makes sense, as the purpose of orientable sensors is to keep the sensor orientation in sync with the screen orientation.
The orientation values range from 0 to 270 degrees. The orientation is applied in clockwise direction, e.g. an orientation value of 90 degrees means that the screen has been rotated 90 degress to the right from its origin position, to compensate a device rotation of 90 degrees to the left.
另请参阅
QSensorReading
QSensor
(
type
[
,
parent=Q_NULLPTR
]
)
¶
- param type
QByteArray- param parent
QObject
Construct the
type
sensor as a child of
parent
.
Do not use this constructor if a derived class exists for the specific sensor type.
The wrong way is to use the base class constructor:
QSensor *magnetometer = new QSensor(QMagnetometer::type, this);
The right way is to create an instance of the derived class:
QMagnetometer *magnetometer = new QMagnetometer(this);
The derived classes have additional properties and data members which are needed for certain features such as geo value support in
QMagnetometer
or acceleration mode support in
QAccelerometer
. These features will only work properly when creating a sensor instance from a
QSensor
子类。
Only use this constructor if there is no derived sensor class available. Note that all built-in sensors have a derived class, so using this constructor should only be necessary when implementing custom sensors, like in the Grue sensor example .
PySide2.QtSensors.QSensor.
Feature
¶
Lists optional features a backend might support.
The features common to all sensor types are:
|
常量 |
描述 |
|---|---|
|
QSensor.Buffering |
The backend supports buffering of readings, controlled by the
|
|
QSensor.AlwaysOn |
The backend supports changing the policy on whether to suspend when idle, controlled by the
|
|
QSensor.SkipDuplicates |
The backend supports skipping of same or very similar successive readings. This can be enabled by setting the
|
The features of
QMagnetometer
是:
|
常量 |
描述 |
|---|---|
|
QSensor.GeoValues |
The backend supports returning geo values, which can be controlled with the
|
The features of
QLightSensor
是:
|
常量 |
描述 |
|---|---|
|
QSensor.FieldOfView |
The backend specifies its field of view, which can be read from the
|
The features of
QAccelerometer
是:
|
常量 |
描述 |
|---|---|
|
QSensor.AccelerationMode |
The backend supports switching the acceleration mode of the acceleromter with the
|
The features of
QPressureSensor
是:
|
常量 |
描述 |
|---|---|
|
QSensor.PressureSensorTemperature |
The backend provides the pressure sensor’s die temperature |
所有可定向传感器特征:
|
常量 |
描述 |
|---|---|
|
QSensor.AxesOrientation |
The backend supports changing the axes orientation from the default of
|
另请参阅
PySide2.QtSensors.QSensor.
AxesOrientationMode
¶
Describes how reading values are affected by the screen orientation.
|
常量 |
描述 |
|---|---|
|
QSensor.FixedOrientation |
No automatic rotation is applied to the reading values. |
|
QSensor.AutomaticOrientation |
The reading values are automatically rotated based on the screen orientation. |
|
QSensor.UserOrientation |
The reading values are rotated based on the angle of the
|
另请参阅
PySide2.QtSensors.QSensor.
activeChanged
(
)
¶
PySide2.QtSensors.QSensor.
addFilter
(
filter
)
¶
filter
–
QSensorFilter
Add a
filter
to the sensor.
The sensor does not take ownership of the filter.
QSensorFilter
will inform the sensor if it is destroyed.
另请参阅
PySide2.QtSensors.QSensor.
alwaysOnChanged
(
)
¶
PySide2.QtSensors.QSensor.
availableDataRates
(
)
¶
PySide2.QtSensors.QSensor.
availableSensorsChanged
(
)
¶
PySide2.QtSensors.QSensor.
axesOrientationMode
(
)
¶
PySide2.QtSensors.QSensor.
axesOrientationModeChanged
(
axesOrientationMode
)
¶
axesOrientationMode
–
AxesOrientationMode
PySide2.QtSensors.QSensor.
backend
(
)
¶
PySide2.QtSensors.QSensor.
bufferSize
(
)
¶
int
另请参阅
PySide2.QtSensors.QSensor.
bufferSizeChanged
(
bufferSize
)
¶
bufferSize
–
int
PySide2.QtSensors.QSensor.
busyChanged
(
)
¶
PySide2.QtSensors.QSensor.
connectToBackend
(
)
¶
bool
Try to connect to a sensor backend.
Returns true if a suitable backend could be found, false otherwise.
The type must be set before calling this method if you are using
QSensor
directly.
PySide2.QtSensors.QSensor.
currentOrientation
(
)
¶
int
PySide2.QtSensors.QSensor.
currentOrientationChanged
(
currentOrientation
)
¶
currentOrientation
–
int
PySide2.QtSensors.QSensor.
dataRate
(
)
¶
int
另请参阅
PySide2.QtSensors.QSensor.
dataRateChanged
(
)
¶
PySide2.QtSensors.QSensor.
defaultSensorForType
(
type
)
¶
type
–
QByteArray
QByteArray
Returns the default sensor identifier for
type
. This is set in a config file and can be overridden if required. If no default is available the system will return the first registered sensor for
type
.
Note that there is special case logic to prevent the generic plugin’s backends from becoming the default when another backend is registered for the same type. This logic means that a backend identifier starting with
generic.
will only be the default if no other backends have been registered for that type or if it is specified in
Sensors.conf
.
PySide2.QtSensors.QSensor.
description
(
)
¶
unicode
PySide2.QtSensors.QSensor.
efficientBufferSize
(
)
¶
int
PySide2.QtSensors.QSensor.
efficientBufferSizeChanged
(
efficientBufferSize
)
¶
efficientBufferSize
–
int
PySide2.QtSensors.QSensor.
error
(
)
¶
int
PySide2.QtSensors.QSensor.
filters
(
)
¶
Returns the filters currently attached to the sensor.
另请参阅
PySide2.QtSensors.QSensor.
identifier
(
)
¶
QByteArray
另请参阅
PySide2.QtSensors.QSensor.
isActive
(
)
¶
bool
PySide2.QtSensors.QSensor.
isAlwaysOn
(
)
¶
bool
PySide2.QtSensors.QSensor.
isBusy
(
)
¶
bool
PySide2.QtSensors.QSensor.
isConnectedToBackend
(
)
¶
bool
PySide2.QtSensors.QSensor.
isFeatureSupported
(
feature
)
¶
feature
–
Feature
bool
Checks if a specific feature is supported by the backend.
QtSensors supports a rich API for controlling and providing information about sensors. Naturally, not all of this functionality can be supported by all of the backends.
To check if the current backend supports the feature
feature
, call this function.
The backend needs to be connected, otherwise false will be returned. Calling
connectToBackend()
or
start()
will create a connection to the backend.
Backends have to implement
isFeatureSupported()
to make this work.
Returns whether or not the feature is supported if the backend is connected, or false if the backend is not connected.
PySide2.QtSensors.QSensor.
maxBufferSize
(
)
¶
int
另请参阅
PySide2.QtSensors.QSensor.
maxBufferSizeChanged
(
maxBufferSize
)
¶
maxBufferSize
–
int
PySide2.QtSensors.QSensor.
outputRange
(
)
¶
int
另请参阅
PySide2.QtSensors.QSensor.
outputRanges
(
)
¶
PySide2.QtSensors.QSensor.
reading
(
)
¶
QSensorReading
PySide2.QtSensors.QSensor.
readingChanged
(
)
¶
PySide2.QtSensors.QSensor.
removeFilter
(
filter
)
¶
filter
–
QSensorFilter
移除
filter
from the sensor.
另请参阅
PySide2.QtSensors.QSensor.
sensorError
(
error
)
¶
error
–
int
PySide2.QtSensors.QSensor.
sensorTypes
(
)
¶
Returns a list of all sensor types.
PySide2.QtSensors.QSensor.
sensorsForType
(
type
)
¶
type
–
QByteArray
Returns a list of ids for each of the sensors for
type
. If there are no sensors of that type available the list will be empty.
PySide2.QtSensors.QSensor.
setActive
(
active
)
¶
active
–
bool
另请参阅
PySide2.QtSensors.QSensor.
setAlwaysOn
(
alwaysOn
)
¶
alwaysOn
–
bool
另请参阅
PySide2.QtSensors.QSensor.
setAxesOrientationMode
(
axesOrientationMode
)
¶
axesOrientationMode
–
AxesOrientationMode
PySide2.QtSensors.QSensor.
setBufferSize
(
bufferSize
)
¶
bufferSize
–
int
另请参阅
PySide2.QtSensors.QSensor.
setCurrentOrientation
(
currentOrientation
)
¶
currentOrientation
–
int
Sets the current screen orientation to
currentOrientation
. This is to be called from the backend whenever the screen orientation or the
userOrientation
特性改变。
另请参阅
PySide2.QtSensors.QSensor.
setDataRate
(
rate
)
¶
rate
–
int
另请参阅
PySide2.QtSensors.QSensor.
setEfficientBufferSize
(
efficientBufferSize
)
¶
efficientBufferSize
–
int
Sets the efficient buffer size to
efficientBufferSize
. This is to be called from the backend.
PySide2.QtSensors.QSensor.
setIdentifier
(
identifier
)
¶
identifier
–
QByteArray
另请参阅
PySide2.QtSensors.QSensor.
setMaxBufferSize
(
maxBufferSize
)
¶
maxBufferSize
–
int
Sets the maximum buffer size to
maxBufferSize
. This is to be called from the backend.
另请参阅
PySide2.QtSensors.QSensor.
setOutputRange
(
index
)
¶
index
–
int
另请参阅
PySide2.QtSensors.QSensor.
setSkipDuplicates
(
skipDuplicates
)
¶
skipDuplicates
–
bool
Sets the duplicate skipping to
skipDuplicates
.
另请参阅
PySide2.QtSensors.QSensor.
setUserOrientation
(
userOrientation
)
¶
userOrientation
–
int
另请参阅
PySide2.QtSensors.QSensor.
skipDuplicates
(
)
¶
bool
另请参阅
PySide2.QtSensors.QSensor.
skipDuplicatesChanged
(
skipDuplicates
)
¶
skipDuplicates
–
bool
PySide2.QtSensors.QSensor.
start
(
)
¶
bool
Start retrieving values from the sensor. Returns true if the sensor was started, false otherwise.
The sensor may fail to start for several reasons.
Once an application has started a sensor it must wait until the sensor receives a new value before it can query the sensor’s values. This is due to how the sensor receives values from the system. Sensors do not (in general) poll for new values, rather new values are pushed to the sensors as they happen.
For example, this code will not work as intended.
sensor->start();
sensor->reading()->x(); // no data available
To work correctly, the code that accesses the reading should ensure the
readingChanged()
信号已被发射。
connect(sensor, SIGNAL(readingChanged()), this, SLOT(checkReading()));
sensor->start();
}
void MyClass::checkReading() {
sensor->reading()->x();
另请参阅
busy
PySide2.QtSensors.QSensor.
stop
(
)
¶
Stop retrieving values from the sensor.
This releases the sensor so that other processes can use it.
另请参阅
busy
PySide2.QtSensors.QSensor.
type
(
)
¶
QByteArray
PySide2.QtSensors.QSensor.
userOrientation
(
)
¶
int
另请参阅
PySide2.QtSensors.QSensor.
userOrientationChanged
(
userOrientation
)
¶
userOrientation
–
int